Mar*_*nio 124 html javascript css jquery
我需要使用Javascript禁用DIV及其所有内容.我可以发誓这样做很简单
<div disabled="true">
Run Code Online (Sandbox Code Playgroud)
以前为我工作,但由于某种原因,它不再有效.我不明白为什么.
在IE10中:"Click Me"文本不显示,单击处理程序仍然有效.
我实际上需要这个工作IE10.以下是我的代码.提前致谢.
<html>
<script>
function disableTest(){
document.getElementById("test").disabled = true;
var nodes = document.getElementById("test").getElementsByTagName('*');
for(var i = 0; i < nodes.length; i++){
nodes[i].disabled = true;
}
}
</script>
<body onload="disableTest();">
<div id="test">
<div onclick="alert('hello');">
Click Me
</div>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
小智 285
以下css语句禁用单击事件
pointer-events:none;
Run Code Online (Sandbox Code Playgroud)
Dan*_*ger 56
试试这个!
$("#test *").attr("disabled", "disabled").off('click');
Run Code Online (Sandbox Code Playgroud)
我没有看到你使用上面的jquery,但你把它列为标签.
我认为内联脚本很难停止,你可以试试这个:
<div id="test">
<div>Click Me</div>
</div>
Run Code Online (Sandbox Code Playgroud)
和脚本:
$(function () {
$('#test').children().click(function(){
alert('hello');
});
$('#test').children().off('click');
});
Run Code Online (Sandbox Code Playgroud)
纯javascript没有jQuery
function sah() {
$("#div2").attr("disabled", "disabled").off('click');
var x1=$("#div2").hasClass("disabledDiv");
(x1==true)?$("#div2").removeClass("disabledDiv"):$("#div2").addClass("disabledDiv");
sah1(document.getElementById("div1"));
}
function sah1(el) {
try {
el.disabled = el.disabled ? false : true;
} catch (E) {}
if (el.childNodes && el.childNodes.length > 0) {
for (var x = 0; x < el.childNodes.length; x++) {
sah1(el.childNodes[x]);
}
}
}
Run Code Online (Sandbox Code Playgroud)
#div2{
padding:5px 10px;
background-color:#777;
width:150px;
margin-bottom:20px;
}
.disabledDiv {
pointer-events: none;
opacity: 0.4;
}
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<div id="div1">
<div id="div2" onclick="alert('Hello')">Click me</div>
<input type="text" value="SAH Computer" />
<br />
<input type="button" value="SAH Computer" />
<br />
<input type="radio" name="sex" value="Male" />Male
<Br />
<input type="radio" name="sex" value="Female" />Female
<Br />
</div>
<Br />
<Br />
<input type="button" value="Click" onclick="sah()" />
Run Code Online (Sandbox Code Playgroud)