table选中的行以指定颜色高亮显示 function IniEvent() { var tbl = document.getElementById("tblMain"); var trs = tbl.getElementsByTagName_.docx w:tbl javascript">
当前位置:   article > 正文

javascript (table选中的行以指定颜色高亮显示)_.docx w:tbl javascript

.docx w:tbl javascript
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
    <title>table选中的行以指定颜色高亮显示</title>
    <script type="text/javascript">
        function IniEvent() {
            var tbl = document.getElementById("tblMain");
            var trs = tbl.getElementsByTagName("tr");
            for (var i = 0; i < trs.length; i++) {
                trs[i].onclick = TrOnClick;
            }
        }
        function TrOnClick() {
            var tbl = document.getElementById("tblMain");
            var trs = tbl.getElementsByTagName("tr");
            for (var i = 0; i < trs.length; i++) {
                if (trs[i] == this) {             //判断是不是当前选择的行
                    trs[i].style.background = "yellow";
                }
                else {
                    trs[i].style.background = "white";
                }
            }
        }
    </script>
</head>
<body οnlοad="IniEvent()">
    <table id="tblMain" border="1">
        <tr>
            <td>1</td>
            <td>三星</td>
            <td>AA</td>
        </tr>
        <tr>
            <td>2</td>
            <td>Norkia</td>
            <td>BB</td>
        </tr>
        <tr>
            <td>3</td>
            <td>苹果</td>
            <td>CC</td>
        </tr>
        <tr>
            <td>4</td>
            <td>联想</td>
            <td>DD</td>
        </tr>
    </table>
</body>
</html>
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/114492
推荐阅读
相关标签
  

闽ICP备14008679号