Javascritp是否能这样判断呢? if (document.getElementById("top1").style.display=='none' ) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 原因在于执行顺序问题这些先于你的HTML代码中id为top1的tr所以找不到对象报错放到后面或放到一个function中,在onload调用<script>if (document.top1.style.display=='' ){document.write("1----")}if (document.top1.style.display=='none' ){document.write("2----")}</script> <script>function f1(){ if (document.all.top1.style.display=="") { document.write("1----"); } if (document.all.top1.style.display=="none") { document.write("2----"); }}</script><body onload="f1()"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td><a href="javascript:;" onClick="top1.style.display=''" >sadfsadfasdfaf</a> </td> </tr><tr id="top1" style='display:none'> <td><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td>1</td> </tr> <tr> <td>2</td> </tr> </table></td> </tr></table></body> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td><a href="javascript:;" onClick="top1.style.display=''" >sadfsadfasdfaf</a> </td> </tr><tr id="top1" style='display:none'> <td><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td>1</td> </tr> <tr> <td>2</td> </tr> </table></td> </tr> <script>if (document.getElementById("top1").style.display=='none' )document.write("2----")elsedocument.write("1----")</script></table> 利用function定义成函数再调用,但是表格不显示了啊~只有输出1----,我是想实现动态显示和隐藏表格,然后根据两种状态输出不出的内容. 通过innerHTML实现<script>function f1(){ if (document.all.top1.style.display=="none") document.getElementById("div1").innerHTML="为none时输出的"else document.getElementById("div1").innerHTML="不为none时输出的"}</script><body onload="f1()"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td><a href="javascript:;" onClick="top1.style.display=''" >sadfsadfasdfaf</a> </td> </tr><tr id="top1" style='display:none'> <td><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td>1</td> </tr> <tr> <td>2</td> </tr> </table></td> </tr></table><div id="div1"> </div></body> jquery.treeview 有人用过这个插件吗 有个传参问题 js中 mootools remove() 对象不支持次方法或属性 "remove" 求助中··· 帮忙看下这个滚动条的顺序 关于jquery.autocomplete控件 有没有哪位大侠用SVG的呀?用这个做电子地图?? onuload事件怎么失效了? 关于QueryString的问题,我为什么打开网页出错呢? 请问如何将小写金额转换成大写金额? 请问能否让页面上每个按钮的onclick都响应同一个事件? 请问一个关于对象引用的问题(在线请教!) 如何删除Script节点元素 如何判断一组输入框中输入数据是否有相同的?
这些先于你的HTML代码中id为top1的tr
所以找不到对象报错
放到后面或放到一个function中,在onload调用
<script>
if (document.top1.style.display=='' ){
document.write("1----")
}
if (document.top1.style.display=='none' ){
document.write("2----")
}
</script>
function f1()
{
if (document.all.top1.style.display=="")
{
document.write("1----");
}
if (document.all.top1.style.display=="none")
{
document.write("2----");
}
}
</script>
<body onload="f1()">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><a href="javascript:;" onClick="top1.style.display=''" >sadfsadfasdfaf</a>
</td>
</tr>
<tr id="top1" style='display:none'>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>1</td>
</tr>
<tr>
<td>2</td>
</tr>
</table></td>
</tr>
</table>
</body>
<tr>
<td>
<a href="javascript:;" onClick="top1.style.display=''" >sadfsadfasdfaf</a>
</td>
</tr>
<tr id="top1" style='display:none'>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>1</td>
</tr>
<tr>
<td>2</td>
</tr>
</table></td>
</tr>
<script>
if (document.getElementById("top1").style.display=='none' )
document.write("2----")
else
document.write("1----")
</script>
</table>
<script>
function f1()
{
if (document.all.top1.style.display=="none")
document.getElementById("div1").innerHTML="为none时输出的"
else
document.getElementById("div1").innerHTML="不为none时输出的"
}
</script>
<body onload="f1()">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><a href="javascript:;" onClick="top1.style.display=''" >sadfsadfasdfaf</a>
</td>
</tr>
<tr id="top1" style='display:none'>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>1</td>
</tr>
<tr>
<td>2</td>
</tr>
</table></td>
</tr>
</table>
<div id="div1">
</div>
</body>