<form id="target">
....
</form>
prop()
方法来禁用类似于disabled的东西。请参阅他们的API页面。
要禁用'target'内部的所有表单元素,请使用:input选择器,它匹配所有输入、文本区域、选择和按钮元素。$("#target :input").prop("disabled", true);
如果您只想要{{p}}元素,请使用此方法。
$("#target input").prop("disabled", true);
更简洁的方法是使用它们的选择器引擎。 因此,要禁用 div 或表单父级中的所有表单元素。
$myForm.find(':input:not(:disabled)').prop('disabled',true)
你可以添加
<fieldset class="fieldset">
然后你可以调用
$('.fieldset').prop('disabled', true);
通过这一行代码,您可以禁用表单中的任何输入字段。
$('form *').prop('disabled', true);
禁用所有表单,只需简单的编写:
jQuery 1.6+
$("#form :input").prop("disabled", true);
jQuery 1.5及以下版本
$("#form :input").attr('disabled','disabled');
你可以像这样做:
//HTML BUTTON
<button type="button" onclick="disableAll()">Disable</button>
//Jquery function
function disableAll() {
//DISABLE ALL FIELDS THAT ARE NOT DISABLED
$('form').find(':input:not(:disabled)').prop('disabled', true);
//ENABLE ALL FIELDS THAT DISABLED
//$('form').find(':input(:disabled)').prop('disabled', false);
}
关于 jQuery API 在 1.6 版本中的更改,Gnarf 给出了权威答案。
$("#target :input").prop("disabled", true);
。 - danijel$(this).closest('form').find('input').prop('disabled', true);
。不确定是否可以更好地整合,我在jQuery方面还是新手。 - wjervis