js-行事件

没有实现 除去表头选中

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8" />
    <style type="text/css">
        table {
            cursor: pointer;
        }
    </style>
</head>
<body>

    <table id='table1' width="100%" border="2" cellspacing="0" cellpadding="0">
    <thead>
        <tr>
            <th>A</th>
            <th>B</th>
            <th>C</th>
            <th>D</th>
        </tr>

    </thead>
    <tbody>
        <tr>
            <td>11</td>
            <td>22</td>
            <td>33</td>
            <td>44</td>
        </tr>
        <tr>
            <td>11a</td>
            <td>22s</td>
            <td>33d</td>
            <td>44f</td>
        </tr>
        <tr>
            <td>1v1</td>
            <td>2d2</td>
            <td>3vv3</td>
            <td>4ff4</td>
        </tr>
        <tr>
            <td>11ww</td>
            <td>w22</td>
            <td>dff33</td>
            <td>4g4</td>
        </tr>
    </tbody>

    </table>



    <SCRIPT LANGUAGE="JavaScript">
        var trs = document.getElementById('table1').getElementsByTagName('tr');
        window.onload = function(){
            for( var i=0; i<trs.length; i++ ){
                trs[i].onmousedown = function(){
                    tronmousedown(this);
                }
            }
        }
        function tronmousedown(obj){
            for( var o=0; o<trs.length; o++ ){
                if( trs[o] == obj ){
                    trs[o].style.backgroundColor = '#DFEBF2';
                }
                else{
                    trs[o].style.backgroundColor = '';
                }
            }
        }
    </SCRIPT>


</body>
</html>

 

posted @ 2015-11-02 16:27  rysly  阅读(235)  评论(0编辑  收藏  举报