ily*_*oli 8 html javascript jquery
我的问题很简单
$('#button').removeAttr('type');
Run Code Online (Sandbox Code Playgroud)
在firebug上触发错误
type property can't be changed
Run Code Online (Sandbox Code Playgroud)
我有两个问题:
谢谢
编辑
我想做的是:
阻止按钮提交表单.
注意:我的按钮作为html模板包含在内,表单代码无法从我这里访问.
就像是:
include 'form.php';
include 'buttons.php';
Run Code Online (Sandbox Code Playgroud)
我只能在buttons.php上控制
Esa*_*ija 17
你不能更改input的type已经插入到DOM之后在IE(<9?).由于这个原因,jQuery会为所有浏览器引发错误.
来自:
set: function( elem, value ) {
// We can't allow the type property to be changed (since it causes problems in IE)
if ( rtype.test( elem.nodeName ) && elem.parentNode ) {
jQuery.error( "type property can't be changed" );
Run Code Online (Sandbox Code Playgroud)
没有其他我知道的情况(或jQuery知道)以及如何解决这个问题在很大程度上取决于你首先要做的事情.考虑创建一个具有不同类型的新元素并使用它.
编辑:要阻止按钮提交表单,您可以使用:
$("#button").click(function(e){
e.preventDefault();
});
Run Code Online (Sandbox Code Playgroud)
或者(信贷Tim Down):
$("#button").prop("disabled", true);
Run Code Online (Sandbox Code Playgroud)
为防止通过任何方式提交表单,您可以使用:
$("#form").submit(function(e){
e.preventDefault();
});
Run Code Online (Sandbox Code Playgroud)
你可以替换它:
$('#button').replaceWith('<input type="text" value="text"/>');
Run Code Online (Sandbox Code Playgroud)
或使用 event.preventDefault()
| 归档时间: |
|
| 查看次数: |
2364 次 |
| 最近记录: |