如何让 table  选中一行 数据

解决方案 »

  1.   

    <title>theforever_csdn碧海情天_赵亮编写的选中指定TABLE行</title>
    <style>
    .trSel {background:grey;}
    .trNotSel {background:white;}
    </style>
    <script>
    function theforever_csdn(n) {
    var tb=document.getElementById("theforever_csdn_table");
    switch(n){
    case 1:tb.rows[0].className="trSel";tb.rows[1].className="trNoSel";break;
    case 2:tb.rows[1].className="trSel";tb.rows[0].className="trNoSel";break;
    }
    }
    </script>
    </head>
    <body>
    <table id="theforever_csdn_table">
    <tr><td>1</td><td>2</td><td>3</td></tr>
    <tr><td>A</td><td>B</td><td>C</td></tr>
    </table>
    <input type="button" value="选中第1行" onclick="theforever_csdn(1);">
    <input type="button" value="选中第2行" onclick="theforever_csdn(2);">
    </body>
    </html>