在table中tr标签中有一个onclick()事件,

在table中tr标签中有一个onclick()事件,

问题描述:

现在我点击tr下的任一个td都会触发事件,怎么才能让第一个td不触事件

 <table>
            <tr onclick="函数">
                    <td><input type="checkbox" ……/></td>
                    <td></td>
                    ……这里有n个td
                    <td></td>
                    <td></td>
                    <td></td>
            </tr>
 </table>

 <table>
            <tr style="border:1px solid red">
                    <td style="border:1px solid blue;width:40px;height:20px">1</td>
                    <td style="border:1px solid blue;width:40px;height:20px">2</td>
                    <td style="border:1px solid blue;width:40px;height:20px">3</td>
                    <td style="border:1px solid blue;width:40px;height:20px">4</td>
                    <td style="border:1px solid blue;width:40px;height:20px">5</td>
            </tr>
    </table>
    <script type="text/javascript">
        $(function()
        {
            $("tr td").not("tr td:first-child").bind('click',function()
            {
                alert($(this).text());
            })
        })
    </script>

两种方式
第一种

function tr_click(e){
  if(e.target.cellIndex!=0){
    alert("不是第一个td");
  }
}
 <tr onclick="tr_click(event)">

第二种,
function td_click(event){
event.stopPropagation();
}


把事件不要绑定到tr上

判断一下就可以了,如果是第一个tr 不加载事件,后面同样的逻辑

把事件不要绑定到tr上