我在一个页面上使用了两个复选框(test1 和 test2),我想编写一个 JavaScript 代码,如果另一个被选中则禁用一个。它工作正常。但当框为只读时,我需要 text
灰色。
这是我的代码
<div class="auto_pick">
<input name="ch0" type="checkbox" value="" id="ch0" align="left" onclick="if (this.checked) document.getElementById('ch1').disabled=true; else document.getElementById('ch1').disabled = false;" style="float:left; margin-right:5px;" />
Test1</div>
<div class="auto_pick1">
<input name="ch1" type="checkbox" value="" id="ch1" align="left" onclick="if (this.checked) document.getElementById('ch0').disabled=true; else document.getElementById('ch0').disabled = false;" style="float:left; margin-right:5px;" />
Test2</div>
最佳答案
您好,对文本使用 span 类。
<div class="auto_pick">
<input name="ch0" type="checkbox" value="" id="ch0" align="left" />
Test1</div>
<div class="auto_pick1">
<input name="ch1" type="checkbox" value="" id="ch1" align="left" />
<span id="text">Test2 </span></div>
Jquery代码
$(function(){
$("#ch0").click ( function() {
if ( $(this).is ( ":checked" ) )
{
$("#ch1").attr ( "disabled" , true);
$("#text").css("color","grey");
}
else
{
$("#ch1").removeAttr ( "disabled" ,true);
$("#text").css("color","black");
}
});
});
关于jquery - 复选框中的错误已禁用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9613826/