如下代码,要求是:点击checkbox时,对应的部分变灰调。不知道哪里出错了,行不通,大家帮我看下
form中间的部分省略了,都是一些table之类的,elements[]中的值也是根据form所包含的元素个数得来的。
<SCRIPT lanugage="javascript">
function dnsdhcp()
{
var method = document.getElementById("tcpip");
if(document.getElementById(dns_get_addr_dhcp).checked == true)
{
method.elements[14].disabled=true;
method.elements[16].disabled=true;
}
else
{
method.elements[14].disabled=false;
method.elements[16].disabled=false;
}
}
</SCRIPT><form name= "tcpip" method="post">
......
<td width=50% nowrap>
<b><font size=-1>Get DNS Server Address from DHCP</font></b></td>
<td width=50%>
<font size=-1>
<input name="dns_get_addr_dhcp" type=checkbox value="1" onclick="dnsdhcp()" > Enable
</font>
</td>
</form>
form中间的部分省略了,都是一些table之类的,elements[]中的值也是根据form所包含的元素个数得来的。
<SCRIPT lanugage="javascript">
function dnsdhcp()
{
var method = document.getElementById("tcpip");
if(document.getElementById(dns_get_addr_dhcp).checked == true)
{
method.elements[14].disabled=true;
method.elements[16].disabled=true;
}
else
{
method.elements[14].disabled=false;
method.elements[16].disabled=false;
}
}
</SCRIPT><form name= "tcpip" method="post">
......
<td width=50% nowrap>
<b><font size=-1>Get DNS Server Address from DHCP</font></b></td>
<td width=50%>
<font size=-1>
<input name="dns_get_addr_dhcp" type=checkbox value="1" onclick="dnsdhcp()" > Enable
</font>
</td>
</form>
elements[16]
对应的是什么元素啊
LZ最好给元素加个id,这样清楚啊
elements[16] 这个是遍历得来的,不可以么?
<b>TCP/IP Settings</b>
<table bgcolor="#FFFFFF" border=1 cellspacing=0 cellpadding=0 width=100%>
<tr>
<td>
<table bgcolor="#FFFFFF" border=0 cellspacing=0 cellpadding=4 width=100%>
<tr>
<td width=50% nowrap><b><font size=-1>Host Name</font></b></td>
<td width=50%>
<font size=-1>
<input name=Host_Name type=text value=name size=14 maxlength=14 >
</font>
</td>
</tr>
<tr>
<td colspan=2 style="border-width: 0px; border-top-width: 2px; border-style: solid; border-color: #c0c0c0">
<font size=-1><b>IPv4</font></b>
</td>
</tr>
<tr>
<td width=40%><font size=-1><b> IP Address Mode </font></b></td>"));
<td width=40%>
<select name = Ip_Addr_Mode >
...........
</select>
</td>
</tr>
<tr>
<td width=50% nowrap><b><font size=-1>Manual IP Address<sup> *1 </sup></font></b></td>
<td width=50%>
<input name=IP_Addr1 type=text .... >
.
<input name=IP_Addr2 type=text ...>
.
<input name=IP_Addr3 type=text ...>
.
<input name=IP_Addr4 type=text ... >
</td>
</tr>
<tr>
<td width=50% nowrap><b><font size=-1>Manual Subnet Mask<sup> *1 </sup></font></b></td>
<td width=50%>
<input name=SubMask_Addr1 type=text ... >
.
<input name=SubMask_Addr2 type=text ... >
.
<input name=SubMask_Addr3 type=text ... >
.
<input name=SubMask_Addr4 type=text ... >
</td>
</tr>
<tr>
<td width=50% nowrap><b><font size=-1>Manual Gateway Address<sup> *1 </sup></font></b></td>
<td width=50%>
<input name=GateWay_Addr1 type=text value=... >
.
<input name=GateWay_Addr2 type=text value=... >
.
<input name=GateWay_Addr3 type=text value=...>
.
<input name=GateWay_Addr4 type=text value=... >
</td>
</tr>
</table>
</td>
</tr>
</table>
<b><font><sup> *1 </sup>for Manually Set only</font></b>
<br><b>DNS</b>
<table bgcolor="#FFFFFF" border=1 cellspacing=0 cellpadding=0 width=100%><tr><td>
<table bgcolor="#FFFFFF" border=0 cellspacing=0 cellpadding=4 width=100%>
<tr>
<td width=50% nowrap><b><font size=-1>DNS Domain Name<sup> *2 </sup></font></b></td>
<td width=50%>
<font size=-1>
<input name=Dns_Domain_Name type=text ... >
</font>
</td>
</tr> <tr>
<td nowrap colspan=2 style="border-width: 0px; border-top-width: 2px; border-style: solid; border-color: #c0c0c0">
<b><font size=-1><b><font size=-1>IPv4</font></b>
</td>
</tr>
<tr>
<td width=50% nowrap><b><font size=-1>Get DNS Server Address from DHCP</font></b></td>
<td width=50%><font size=-1>
<input name="dns_get_addr_dhcp" type=checkbox value="1" onclick="dnsdhcp()" > Enable
</font></td></tr>
<tr>
<td width=50% nowrap><b><font size=-1>DNS Server Address<sup> *2 </sup></font></b></td>
<td width=50%>
<font size=-1>
<input name=Dns_Server_Addr1 type=text....>
.
<input name=Dns_Server_Addr2 type=text .... >
.
<input name=Dns_Server_Addr3 type=text ....>
.
<input name=Dns_Server_Addr4 type=text .... ></font></td>
</tr>
</table>
</td></tr></table>
</form>
是想让DNS Domain Name和DNS Server Address部分变灰色
LZ只有<input name="dns_get_addr_dhcp" type=checkbox value="1" onclick="dnsdhcp()" >
这个元素并没有id属性还有dns_get_addr_dhcp要改成'dns_get_addr_dhcp'