javascript 为空或不是对象 在线等
想让行tr1的display属性为none;
可是运行的时候报错,document.Form1.tr.style为空或不是对象,javascript怎么这么容易出错呢,有的时候代码一样,可是换个机子就不能运行了,在线等,谢谢
function show()
{
//document.Form1.Text1.value=document.Form1.Text2.value;
document.Form1.tr1.style.display= "none ";
switch(document.Form1.Text2.value)
{
// case '1 ':document.Form1.Text1.value=2;document.Form1.tr1.style.display= "none ";break;
//case '2 ':document.Form1.Text1.value=2;
}
}
</script>
</HEAD>
<body MS_POSITIONING= "GridLayout " >
<form id= "Form1 " method= "post " runat= "server ">
< <INPUT id= "Text1 " style= "Z-INDEX: 102; LEFT: 40px; POSITION: absolute; TOP: 48px " type= "text "
name= "Text1 " runat= "server ">
<TABLE id= "Table1 " style= "Z-INDEX: 103; LEFT: 184px; POSITION: absolute; TOP: 208px " cellSpacing= "1 "
cellPadding= "1 " width= "300 " border= "1 ">
<TR id= "tr1 " >
<TD> lilia <INPUT type= "text "> </TD>
<TD> df <INPUT type= "text "> d </TD>
<TD> df <INPUT type= "text "> df </TD>
</TR>
<TR id= "2 ">
<TD> dfd </TD>
<TD> fdfd </TD>
<TD> fdfd </TD>
</TR>
<TR id= "3 ">
<TD> dfdsa </TD>
<TD> dfd </TD>
<TD> fdfd </TD>
</TR>
</TABLE>
<INPUT id= "Text2 " style= "Z-INDEX: 104; LEFT: 216px; POSITION: absolute; TOP: 136px " type= "text "
name= "Text2 " runat= "server ">
<INPUT id= "Button1 " style= "Z-INDEX: 101; LEFT: 232px; POSITION: absolute; TOP: 40px " type= "button "
value= "Butt " onclick= "show() " name= "B1 " runat= "server ">
</form>
</body>
</HTML>
------解决方案--------------------document.Form1.tr1.style.display= "none ";
--->
document.getElementById( "tr1 ').style.display= "none ";
------解决方案--------------------因为这是标准,你写的不是标准,有些环境会不认的
------解决方案--------------------document.Form1.tr1
有这样的DOM吗?
不是js容易出错,是你乱写当然要出错了
------解决方案--------------------你是得不到document.Form1.tr1这个对象
用这个document.Form1是根据name来查找的
------解决方案--------------------document.Form1.tr1.style.display= "none "; //只有IE支持的方式
document.getElementById( "tr1 ').style.display= "none "; //W3C定义的标准方式,所有浏览器都支持