javascript getElementById().disabled=true;

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23688221/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 01:23:50  来源:igfitidea点击:

getElementById().disabled=true;

javascriptbuttongetelementbyiddisabled-control

提问by user3642438

I am trying to disable two icons when one is clicked. Then all the icons are active once it is clicked again. I can't figure this out for the life of me. Any suggestions.I am trying to disable two icons when one is clicked. Then all the icons are active once it is clicked again. I can't figure this out for the life of me. Any suggestions.

我试图在单击一个图标时禁用两个图标。再次单击后,所有图标都处于活动状态。我这辈子都搞不清楚。任何建议。我试图在单击一个图标时禁用两个图标。再次单击后,所有图标都处于活动状态。我这辈子都搞不清楚。有什么建议。

<!--SCRIPT-->
<script language="javascript">

function pic1() {
var img = document.getElementById('img').src;
if (img.indexOf('images/pages/financing.png')!=-1) {
document.getElementById('img').src  = 'images/pages/magnifying_glass.png';
document.getElementById('img2').disabled = true;
document.getElementById('img3').disabled = true;
document.getElementById("case").style.display='block';

}
else {
document.getElementById('img').src = 'images/pages/financing.png';
document.getElementById("case").style.display='none';
}

}

function pic2() {
var img = document.getElementById('img2').src;
if (img.indexOf('images/pages/check.png')!=-1) {
document.getElementById('img1').disabled = true;
document.getElementById('img3').disabled = true
document.getElementById('img2').src  = 'images/pages/magnifying_glass.png';"
}
else {
document.getElementById('img2').src = 'images/pages/check.png';
document.getElementById("case").style.display='none';
}

}

function pic3() {
var img = document.getElementById('img3').src;
if (img.indexOf('images/pages/pen.png')!=-1) {
document.getElementById('img1').disabled = true;
document.getElementById('img2').disabled = true
document.getElementById('img3').src  = 'images/pages/magnifying_glass.png';
}
else {
document.getElementById('img3').src = 'images/pages/pen.png';
document.getElementById("case").style.display='none';
}

}

</script>

<!--CONTENT-->

<div id="icons">
<li class="effect1"><img src="images/pages/financing.png" id="img"           onclick="pic1()"alt="" width="150px" height="150px"><br>FINANCING<p id="text"></p></li>
<li class="effect2"><img src="images/pages/check.png" id="img2" onclick="pic2()" alt=""        width="150px" height="150px"><br>FACTORS<p id="text2"></p></li>
<li class="effect3"><img src="images/pages/pen.png" id="img3" onclick="pic3()" alt=""     width="150px" height="150px"><br>LEASING<p id="text3"></p></li>

</div> <!-- end icons -->

回答by Ben Bartle

It looks like your first image has id "img" not "img1".

看起来您的第一张图片的 ID 为“img”而不是“img1”。