插入 DOM 后,您无法更改 IE (<9?) 中的input
's 。type
因此,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" );
我不知道(或 jQuery 知道)其他情况,如何解决这个问题在很大程度上取决于您首先要尝试做什么。例如,考虑创建一个具有不同类型的新元素并使用它。
编辑:要防止按钮提交表单,您可以使用:
$("#button").click(function(e){
e.preventDefault();
});
或者(信用 Tim Down):
$("#button").prop("disabled", true);
为了防止通过任何方式提交表单,您可以使用:
$("#form").submit(function(e){
e.preventDefault();
});