javascript怎么隐藏行
程序员文章站
2022-03-04 10:32:38
...
javascript隐藏行的方法:1、创建一个HTML示例文件;2、定义一个table表格;3、通过js代码“function setDetailMsgRow(rowID, btn) {...}”实现隐藏table的某一行即可。
本文操作环境:Windows7系统、javascript1.8.5版、Dell G3电脑。
javascript怎么隐藏行?
js控制隐藏或显示table的某一行
主要JS如下:(兼容browser: IE9, FireFox, Chrome, 360 safe)
var row = document.getElementById(rowID); if (row != null) { if (row.style.display == (document.all ? "block" : "table-row")) { row.style.display = "none"; } else { row.style.display = (document.all ? "block" : "table-row"); } }
效果图如下:
全部 HTML:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="testWeb.WebForm1" %> <!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 runat="server"> <title></title> <script language="javascript" type="text/javascript"> function setDetailMsgRow(rowID, btn) { var row = document.getElementById(rowID); if (row != null) { if (row.style.display == (document.all ? "block" : "table-row")) { row.style.display = "none"; } else { row.style.display = (document.all ? "block" : "table-row"); } } if (btn != null) { if (btn.value != "Hide Message") btn.value = "Hide Message"; else btn.value = "Show Message"; } } </script> </head> <body> <form id="form1" runat="server"> <div> <input type="button" οnclick="setDetailMsgRow('tmpRow0',this)" value="Show Message"/> <table border="1"><tr id="tmpRow0" style="display:none;color:Blue"><td>aa</td><td>44aa</td></tr> <tr id="tmpRow1"><td>bb</td><td>44bb</td></tr> <tr id="tmpRow2"><td>cc</td><td>44cc</td></tr> <tr id="tmpRow3"><td>dd</td><td>44dd</td></tr> <tr id="tmpRow4"><td>ee</td><td>44ee</td></tr> </table> </div> </form> </body> </html>
推荐学习:《js基础教程》
以上就是javascript怎么隐藏行的详细内容,更多请关注其它相关文章!