Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
208 views
in Technique[技术] by (71.8m points)

javascript - 在Javascript中启用和禁用Div及其元素[重复](Enable & Disable a Div and its elements in Javascript [duplicate])

This question already has an answer here:(这个问题在这里已有答案:)

How to disable all div content 26 answers(如何禁用所有div内容 26个答案)

I am looking for a method to Enable and Disable the div id="dcalc" and Its children.(我正在寻找一种启用和禁用 div id =“dcalc”及其子项的方法。)

<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 ?(我想在加载页面时禁用它们然后通过单击我可以启用它们吗?) This is what i have tried(这就是我尝试过的) document.getElementById("dcalc").disabled = true;   ask by Emax translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You should be able to set these via the attr() or prop() functions in jQuery as shown below:(您应该能够通过jQuery中的attr()prop()函数设置它们,如下所示:)

jQuery (< 1.7):(jQuery(<1.7):) // This will disable just the div $("#dcacl").attr('disabled','disabled'); or(要么) // This will disable everything contained in the div $("#dcacl").children().attr("disabled","disabled"); jQuery (>= 1.7):(jQuery(> = 1.7):) // This will disable just the div $("#dcacl").prop('disabled',true); or(要么) // This will disable everything contained in the div $("#dcacl").children().prop('disabled',true); or(要么) // disable ALL descendants of the DIV $("#dcacl *").prop('disabled',true); Javascript:(使用Javascript:) // This will disable just the div document.getElementById("dcalc").disabled = true; or(要么) // 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; }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...