function SetTbEnable() {
var tb = document.getElementById("<%=TextBox1.ClientID%>");
var cb = document.getElementById("<%=CheckBox1.ClientID%>");
if (cb.checked == true) {
tb.disabled = false;
}
else {
tb.disabled = true;
tb.style.BackColor = "Gainsboro";
}
}我这样写有错误吗? 为什么没有效果啊 背景色不能为灰色呀。 大家帮忙看看
var tb = document.getElementById("<%=TextBox1.ClientID%>");
var cb = document.getElementById("<%=CheckBox1.ClientID%>");
if (cb.checked == true) {
tb.disabled = false;
}
else {
tb.disabled = true;
tb.style.BackColor = "Gainsboro";
}
}我这样写有错误吗? 为什么没有效果啊 背景色不能为灰色呀。 大家帮忙看看
tb.disabled=true 改为 tb.disabled="disabled";
试试。
想背景变会好似得用滤镜
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<script language="javascript" type="text/javascript">function SetTbEnable() {
var tb = document.getElementById("xx");
var cb = document.getElementById("chk01");
if (cb.checked == true) {
tb.disabled = false;
tb.style.backgroundColor = "";
}else{
tb.disabled = true;
tb.style.backgroundColor = "Gainsboro";
}
}
</script>
<body>
<p>TEST</p>
<p>
<input name="chk01" type="checkbox" id="chk01" value="checkbox" onClick="javascript:SetTbEnable();">选中有效
</p>
<p>
<input name="xx" type="text" id="xx" disabled value="Default value">
</p>
</body>
</html>