我的问题很简单
$('#button').removeAttr('type');
在 firebug 上触发错误
type property can't be changed
我有两个问题:
- 如何解决这个问题?
- 是否有包含无法更改的属性列表的参考?
Thanks
EDIT
我想做的是:
阻止按钮提交表单。
注意:我的按钮作为 html 模板包含在内,我无法访问表单代码。
就像是:
include 'form.php';
include 'buttons.php';
我只能控制按钮.php
你不能改变一个input
's type
在 IE (
来自来源:
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" );
没有其他情况我知道(或 jQuery 知道)以及如何解决这个问题很大程度上取决于您首先想要做什么。例如,考虑创建一个不同类型的新元素并使用它。
编辑:要防止按钮提交表单,您可以使用:
$("#button").click(function(e){
e.preventDefault();
});
或者(由 Tim Down 提供):
$("#button").prop("disabled", true);
为了防止通过任何方式提交表单,您可以使用:
$("#form").submit(function(e){
e.preventDefault();
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)