Js选中checkbox后获取table内一行TD所有数据

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>Untitled</title>
    <script>
        function test(o) {
            if (!o.checked) {
                return;
            }
            var tr = o.parentNode.parentNode;
            var tds = tr.cells;
            var str = "you click ";
            for(var i = 0;i < tds.length;i++){
                if (i < 3) {
                    str = str + tds[i].innerHTML + "--";
                }
            }
            alert(str);
        }
    </script>
</head>
<body>
<table width="60%" cellspacing="0" cellpadding="0" align="left" border="1" bordercolordark="#ffffff" bordercolorlight="#B3B5B4" >
    <tbody id="tabstore1">
        <tr>
            <td>b1</td>
            <td>b2</td>
            <td>b3</td>
            <td><input type="checkbox" onclick="test(this);"/></td>
        </tr>
        <tr>
            <td>c1</td>
            <td>c2</td>
            <td>c3</td>
            <td><input type="checkbox" onclick="test(this);"/></td>
        </tr>
    </tbody>
</table>
</body>
</html>

你可能感兴趣的:(html,function,table,border)