jQuery 禁用/启用 div 中的所有元素

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6961678/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 21:37:14  来源:igfitidea点击:

Disable/enable all elements in div

jqueryhtml

提问by Sergey Metlov

How to make quick disabling/enabling of all the elements in any div (inputs, links and jQ Buttons)?

如何快速禁用/启用任何 div(输入、链接和 jQ 按钮)中的所有元素?

回答by karim79

Links do not have a "disabled" property, so you'll have to work a bit harder.

链接没有“禁用”属性,因此您必须更加努力地工作。

$('#my_div').find(':input').prop('disabled', true);
$('#my_div a').click(function(e) {
    e.preventDefault();
});

To re-activate:

重新激活:

$('#my_div').find(':input').prop('disabled', false);
$('#my_div a').unbind("click");

The :inputselector Selects all input, textarea, select and button elements.

所述:input选择器选择的所有输入,文本区域,选择和按钮元件。

Also see http://api.jquery.com/event.preventDefault/

另见http://api.jquery.com/event.preventDefault/

回答by AlienWebguy

$('#my_div').find('*').prop('disabled',true);

To re-enable, simply use .removeProp()http://api.jquery.com/removeProp/

要重新启用,只需使用.removeProp()http://api.jquery.com/removeProp/

回答by Jacek Kaniuk

$('div').find('input, a, button').prop('disabled', true);

or maybe all:

或者全部:

$('div *').prop('disabled', true);