<tr id="result_tr" style="display: none;"> <script type="text/javascript"> //隱藏TR function hide_tr() { alert("hide"); var result_style = document.getElementById('dyn_tr').style; result_style.display = 'none'; } //顯示TR function show_tr() { alert("show"); var result_style = document.getElementById('dyn_tr').style; result_style.display = 'table-row'; } </script>
以下是完整程式
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <script type="text/javascript"> //隱藏TR function hide_tr() { alert("hide"); var result_style = document.getElementById('dyn_tr').style; result_style.display = 'none'; } //顯示TR function show_tr() { alert("show"); var result_style = document.getElementById('dyn_tr').style; result_style.display = 'table-row'; } </script> <title>未命名 1</title> </head> <body> <table border="1"> <tr><td>1111</td><td>1111</td></tr> <tr id="dyn_tr" style="display: none;"><td>222</td><td>222</td></tr> <tr><td>333</td><td>333</td></tr> </table> <input type="button" value="Hide" onclick="hide_tr()"> <input type="button" value="Show" onclick="show_tr()"> </body> </html>
非常感謝!!!
回覆刪除你這個資料幫助我不少 > <!
感謝你的分享
回覆刪除另,請問如333之後再多一列444也是要隱藏 要如何寫?(222跟444可以分別隱藏/顯示)
講解非常詳細
回覆刪除感謝作者無私的分享~!!