启用&在Javascript中禁用Div及其元素 [英] Enable & Disable a Div and its elements in Javascript
本文介绍了启用&在Javascript中禁用Div及其元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找启用和停用
div id =dcalc及其子女的方法。
I am looking for a method to Enable and Disable the div id="dcalc" and Its children.
<div id="dcalc" class="nerkheArz"
style="left: 50px; top: 150px; width: 380px; height: 370px;
background: #CDF; text-align: center" >
<div class="nerkh-Arz"></div>
<div id="calc"> </div>
</div>
我想在加载页面时禁用它们然后点击一下我可以启用它们吗?
I want to Disable them at loading the page and then by a click i can enable them ?
这就是我试过的事情
document.getElementById("dcalc").disabled = true;
推荐答案
你应该可以通过 attr()
或 prop()
函数如下所示:
You should be able to set these via the attr()
or prop()
functions in jQuery as shown below:
jQuery(< 1.7):
// This will disable just the div
$("#dcacl").attr('disabled','disabled');
或
// This will disable everything contained in the div
$("#dcacl").children().attr("disabled","disabled");
jQuery(> = 1.7):
// This will disable just the div
$("#dcacl").prop('disabled',true);
或
// This will disable everything contained in the div
$("#dcacl").children().prop('disabled',true);
或
// disable ALL descendants of the DIV
$("#dcacl *").prop('disabled',true);
Javascript:
// This will disable just the div
document.getElementById("dcalc").disabled = true;
或
// This will disable all the children of the div
var nodes = document.getElementById("dcalc").getElementsByTagName('*');
for(var i = 0; i < nodes.length; i++){
nodes[i].disabled = true;
}
这篇关于启用&在Javascript中禁用Div及其元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文