此代码在 chrome 中运行时无法禁用列表框...但它在 firefox 中工作...是否有任何通用脚本可在所有浏览器中工作
<script>
function fun()
{
//alert("welcome==>"+document.getElementById("geography").value);
if(document.getElementById("geography").value!=0)
{
document.getElementById("country").disabled=true;
document.getElementById("state").disabled=true;
}
else
{
document.getElementById("country").disabled=false;
document.getElementById("state").disabled=false;
}
}
}
</script>
</head>
<body>
<form name="example" action ="" method="get">
<table>
<tr><td>Geography</td> <td><select name="geography" id="geography"
onchange="fun()">
<option value="0">select</option>
<option value="1">zone</option>
<option value="2">state</option>
<option value="3">city</option>
</select></td></tr>
</table>
<table>
<tr><td>country</td> <td><select name="country" id="country">
<option value="0">select</option>
<option value="1">india</option>
<option value="2">china</option>
<option value="3">pak</option>
</select></td></tr>
</table>
<table>
<tr><td>state</td> <td><select name="state" id="state">
<option value="0">select</option>
<option value="1">tamil</option>
<option value="2">kerala</option>
<option value="3">andra</option>
</select></td></tr>
</body>
请提供解决此问题的任何解决方案...
最佳答案
使用setAttribute和 removeAttribute相反:
document.getElementById("country").setAttribute("disabled", "disabled");
document.getElementById("country").removeAttribute("disabled");
此外,辅助函数可能会稍微清理一下代码:
function setDisabledValue(id, value) {
var elem = document.getElementById(id);
if(value) elem.setAttribute("disabled", "disabled");
else elem.removeAttribute("disabled");
}
setDisabledValue("country", true);
...
关于javascript - 禁用无法正常工作 chrome 浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18785881/