看图,当我点击这个红色圈圈的这个按钮时候,得到它所在行的第一个节点,即是它所在行的那个复选框。
这个js这么写?或者是jquery  ,注意  三个按钮没有id属性。至于为什么没有,他有道理的。不能有id属性,
所以不能   $("#id").。。

解决方案 »

  1.   

    <!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>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script type="text/javascript">
    function change(x){
    var tr=x.parentNode.parentNode;
    var c=tr.firstChild;
    if(!c.tagName){
    c=c.nextSibling;
    }
    c=c.firstChild;
    if(c.checked==true){
    c.checked=false;
    }else{
    c.checked=true;
    }
    }
    </script>
    </head><body>
    <table>
    <tr>
         <td><input type="checkbox" /></td>
            <td>1</td>
            <td><input type="button" value="change" onclick="change(this)"></td>
        </tr>
    <tr>
         <td><input type="checkbox" /></td>
            <td>1</td>
            <td><input type="button" value="change" onclick="change(this)"></td>
        </tr>
    <tr>
         <td><input type="checkbox" /></td>
            <td>1</td>
            <td><input type="button" value="change" onclick="change(this)"></td>
        </tr>
    </table>
    </body>
    </html>
    类似这样试试
      

  2.   

    $(':button').click(function(){
    alert($(this).parents('tr').children(':first').children(':first').val());
    });
      

  3.   

    给个jQuery的简便操作
    $(":button").click(function(){
        var chk = $(this).parents("tr").find("td:first :checkbox");
        console.log(chk.val());
    });
      

  4.   

    不能有ID,那如果可以有class也好办,如果连class也没有,那就用tagName的方式,楼上的方法是可以的。
      

  5.   

    一般没有id的时候就通过其它的属性来去元素,或者考虑是否可以用this,只要得到当前操作的元素,都可以通过层级关系来获取其它的元素,具体的实例前面的大婶都已经给出了
      

  6.   

    获取元素的方法很多种的,不止只有id可以获取,js本身就支持根据name,或者标签来获取
    建议看看jquery的api,看看如何获取自身元素,如何获取兄弟姐妹,父元素等等,看看选择器任何组合的