今天在項目中碰到這個問題,要求用JS寫。我郁悶,網上找了好久才找到相關資料,寫下來供以后參考。
<html>
<head>
<SCRIPT type="text/javascript">
function s(tab1){
if(tab1.style.display == "none")
tab1.style.display="";
else
tab1.style.display = "none";
}
</SCRIPT>
</head>
<body>
<TABLE id="tab1" style="display: none">
<tr>
<td>aaa</td>
<td>bbb</td>
</tr>
</TABLE>
<TABLE>
<tr>
<td>
<INPUT type="button" name="b0" value="sumbit" onclick="s(tab1)">
</td>
</tr>
</TABLE>
</body>
</html>
發現洋式表很強啊,只是我不知道怎么用。
S()方法中傳入要隱藏的表格或其他空間的ID,其實不傳也可以,但是如果有多個BUTTON的響應不同表格的時候,我們只需要改變方法中的參數,而不需要另外寫方法了,例如:
function s(t){
if(t.style.display == "none")
t.style.display="";
else
t.style.display = "none";
}......
<INPUT type="button" name="b0" value="sumbit" onclick="s(tab1)">
<INPUT type="button" name="b0" value="sumbit" onclick="s(tab2)">
<INPUT type="button" name="b0" value="sumbit" onclick="s(tab3)">