开发者

Disable/enable all elements in div [duplicate]

This question already has answers here: How to disable all div content (29 answers) 开发者_StackOverflow中文版 Closed 9 years ago.

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


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 :input selector Selects all input, textarea, select and button elements.

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


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

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


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

or maybe all:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜