Javascript 如何使用 jQuery 禁用 div 或 table 中的所有元素
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8413989/
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
How to disable all Element inside a div or table using jQuery
提问by Arian
I have a table that contains several text box and buttons.I disable my table using jquery by this code:
我有一个包含多个文本框和按钮的表格。我通过以下代码使用 jquery 禁用我的表格:
$("#tbl").attr("disabled", "disabled");
my table become disabled but when I double click on the button it become enable and I can enter characters in my text box too. How I can Disable all control inside a table?
我的表格被禁用,但是当我双击按钮时它会启用,我也可以在我的文本框中输入字符。如何禁用表内的所有控件?
thanks
谢谢
回答by Interrobang
You must traverse and disable all relevant elements.
您必须遍历并禁用所有相关元素。
$("#tbl").find("input,button,textarea,select").attr("disabled", "disabled");
回答by Nishant
use a div to layer over the entire table, essentially making it "unclickable". Checkout the BlockUI plugin for this.
使用 div 在整个表格上分层,基本上使其“不可点击”。为此,请查看 BlockUI 插件。
Read more about it on http://malsup.com/jquery/block/#overview
在http://malsup.com/jquery/block/#overview上阅读更多相关信息
or refer to already discussed topic Disabling controls within a table - JQuery/Javascript
或参考已经讨论过的主题 在表中禁用控件 - JQuery/Javascript
回答by Hemal
I think following code will also be very useful
我认为以下代码也将非常有用
$("YOUR_TABLE").find("*").attr("disabled", "disabled");
回答by clklachu
Please try this
请试试这个
$("#tbl *").attr("disabled",disabled");
Ex:
前任: