|
|
听话的日光灯 · postman 可以做接口并发测试么? - 知乎· 1 年前 · |
|
|
逼格高的领结 · 为什么自己写的注意力机制会比不过torch的 ...· 2 年前 · |
|
|
个性的韭菜 · manual that ...· 2 年前 · |
我正在寻找一种方法来启用和禁用 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>
我想在加载页面时禁用它们,然后单击一下就可以启用它们?
这就是我尝试过的
document.getElementById("dcalc").disabled = true;
您应该能够通过jQuery中的
attr()
或
prop()
函数设置它们,如下所示:
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;
}
以下操作将选择所有子代元素并禁用它们:
$("#dcacl").find("*").prop("disabled", true);
但只有禁用某些元素类型才有意义:输入、按钮等,因此您需要一个更具体的选择器:
$("#dcac1").find(":input").prop("disabled",true);
// noting that ":input" gives you the equivalent of
$("#dcac1").find("input,select,textarea,button").prop("disabled",true);
要重新启用,只需将"disabled“设置为false即可。
我想在加载页面时禁用它们,然后单击即可启用它们
好的,将上面的代码放在一个文档就绪的处理程序中,并设置一个适当的单击处理程序:
$(document).ready(function() {
var $dcac1kids = $("#dcac1").find(":input");
$dcac1kids.prop("disabled",true);
|
|
听话的日光灯 · postman 可以做接口并发测试么? - 知乎 1 年前 |