非常完美崔阿扎告白:初接触js,请教~~总报错

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/29 04:08:57
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<script>
function setlist(abc){
if abc.value=1
{
form1.list1.disabled=false
}
return true
}
</script>
<body>
<form id="form1" name="form1" method="post" action="">
<table width="300" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="64" height="24" align="center">
<input name="a1" onclick="setlist(this)" type="checkbox" id="a1" value="1" /> </td>
<td width="236" height="24"><label>
<select name="list1" id="list1" disabled="disabled">
<option value="1">111111111</option>
<option value="2">222222222</option>
<option value="3">333333333</option>
</select>
</label></td>
</tr>
</table>
</form>
</body>
</html>



if abc.value=1

改成

if (eval(abc).value=1 )

因为javascript会把abc当成对象名,而不是将abc里的值取出来当对象名,这时候就要使用eval()来获取变量值作为对象名。

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<script>
function setlist(abc){

if (abc.value=1)
{
form1.list1.disabled=false
}
else
{
return true
}
}
</script>
<body>
<form id="form1" name="form1" method="post" action="">
<table width="300" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="64" height="24" align="center">
<input name="a1" onclick="setlist(this)" type="checkbox" id="a1" value="1" /> </td>
<td width="236" height="24"><label>
<select name="list1" id="list1" disabled="disabled">
<option value="1">111111111</option>
<option value="2">222222222</option>
<option value="3">333333333</option>
</select>
</label></td>
</tr>
</table>
</form>
</body>
</html>

我测试过了没问题