javascript控制displayIE下正常,火狐不行,什么原因, IE下调试一切正常,Opera下调试可以起作用,但会打乱布局,而火狐下根本就不起作
以下原代码IE下调试一切正常,Opera下调试可以起作用,但会打乱布局,而火狐下根本就不起作用,不知道为何,请达人赐教!!
-----------------------------------------------源代码如下----------------------------------------------------
<script language = "JavaScript ">
function selectusertype()
{
if(document.regform.usertype[0].checked==1){
selectusertypeqy1.style.display= 'none ';
selectusertypeqy2.style.display= 'none ';
selectusertypeqy3.style.display= 'none ';
selectusertypegr1.style.display= 'block ';
selectusertypegr2.style.display= 'block ';
}
else
{
selectusertypeqy1.style.display= 'block ';
selectusertypeqy2.style.display= 'block ';
selectusertypeqy3.style.display= 'block ';
selectusertypegr1.style.display= 'none ';
selectusertypegr2.style.display= 'none ';
}
}
//--
</script>
<form name= "regform " method= "post " action= "reg.asp " onsubmit= "return checkaddpro() ">
<div id= "formwrapper ">
<FIELDSET>
<LEGEND> 用户名及类型 </LEGEND>
<br />
<table width= "600 " border= "0 " align= "center " cellpadding= "0 " cellspacing= "0 ">
<tr>
<td width= "100 " height= "24 " align= "right "> <span style= "color: #666666 "> 用户类型: </span> </td>
<td width= "200 "> <input name= "usertype " type= "radio " value= "1 " checked= "checked " onClick= "selectusertype() " />
<span style= "color: #1e7ace "> 个人用户 </span>
<input type= "radio " name= "usertype " value= "2 " onClick= "selectusertype() " />
<span style= "color: #1e7ace "> 企业用户 </span> </td>
<td> <span style= "color: #666666 "> 请选择您的用户类型。 </span> </td>
</tr>
</table>
<br />
</FIELDSET> <br />
<FIELDSET>
<LEGEND> 基本资料 </LEGEND>
<br />
<table width= "600 " border= "0 " align= "center " cellpadding= "0 " cellspacing= "0 ">
<tr id= "selectusertypegr1 ">
<td width= "100 " height= "24 " align= "right "> <span style= "color: #666666 "> E-mail: </span> </td>
<td width= "200 "> <input type= "text " name= "email " id= "email " size= "25 " maxlength= "30 " /> </td>
<td width= "300 " align= "left "> <div id= "d_email " style= "color: #666666 "> 请输入您常用的电子邮箱地址。 </div> </td>
</tr>
<tr id= "selectusertypegr2 ">
<td width= "100 " height= "24 " align= "right "> <span style= "color: #666666 "> 真实姓名: </span> </td>
<td width= "200 "> <input type= "text " name= "turename " id= "turename " size= "25 " maxlength= "30 " /> </td>
<td width= "300 "> </td>
</tr>
<tr id= "selectusertypeqy1 " style= "display:none; ">
<td width= "100 " height= "24 " align= "right "> <span style= "color: #666666 "> 联 系 人: </span> </td>
<td width= "200 "> <input type= "text " name= "turename " id= "turename " size= "25 " maxlength= "30 " /> </td>
<td width= "300 "> </td>
</tr>
<tr id= "selectusertypeqy2 " style= "display:none; ">
<td width= "100 " height= "24 " align= "right "> <span style= "color: #666666 "> 职 务: </span> </td>
<td width= "200 "> <input type= "text " name= "zw " id= "zw " size= "12 " maxlength= "30 " />
<select name= "Selectpp " onchange= "(document.regform.zw.value=this.options[this.selectedIndex].value) ">
<option selected= "selected "> 选择 </option>
<option value= "董事长 "> 董事长 </option>
<option value= "执行董事 "> 执行董事 </option>
<option value= "总裁 "> 总裁 </option>
<option value= "总经理 "> 总经理 </option>
<option value= "部门经理 "> 部门经理 </option>
</select> </td>
<td width= "300 "> </td>
</tr>
<tr id= "selectusertypeqy3 " style= "display:none; ">
<td width= "100 " height= "24 " align= "right "> <span style= "color: #666666 "> 联系E-mail: </span> </td>
<td width= "200 "> <input type= "text " name= "email " id= "email " size= "25 " maxlength= "30 " /> </td>
<td width= "300 " align= "left "> <div id= "div " style= "color: #666666 "> 请输入您常用的电子邮箱地址。 </div> </td>
</tr>
</table>
<br />
</FIELDSET> <br /> <center>
<input name= "create791 " type= "submit " class= "buttom " value= " 提 交 " />
<input name= "Submit " type= "reset " class= "buttom " value= " 重 置 " /> </center>
</div>
</form>
[解决办法]
FF不支持直接用HTML元素id做变量
需要documnet.getElementById( "selectusertypeqy1 ").style.display= "... ";
[解决办法]
不可以这样得到selectusertypegr2
需要documnet.getElementById( "selectusertypegr2 ")
这个才规范
[解决办法]
补充说明一下:
最好使用:
documnet.getElementById( "selectusertypeqy1 ").style.display= " ";
而不要使用
documnet.getElementById( "selectusertypeqy1 ").style.display= "none ";
----------------------------------
补充说明一下:
最好使用:
documnet.getElementById( "selectusertypeqy1 ").style.display= " ";
而不要使用
documnet.getElementById( "selectusertypeqy1 ").style.display= "block ";
楼主不要搞错,none是用来隐藏的, = " "是显示的, 是不同的,但显示时用block在FF下确实会发生你那情况, 所以直接 = " "就行了
