将not()与表行一起使用

时间:2014-11-10 12:15:13

标签: jquery

我正在做以下事情:

$("#bl tbody").on("click", "tr", function () {
}

只要单击一行,就会执行函数内的代码。

如果点击发生 文本框动态添加到行中,如何阻止代码执行?

2 个答案:

答案 0 :(得分:2)

你可以试试这个:

$("#bl tbody").on("click", "tr", function () {
  // your code in this block
}).on("click", "input[type='text']", function (e) { // chain this
   e.stopPropagation(); // stops the event to bubbleup
})

答案 1 :(得分:2)

一种解决方案是排除input文字,如:

$("table tr").on("click", function(event) {
  if (event.target.type != "text")
    alert("ok");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
  <tr>
    <td>
      <input type="text" />
    </td>
    <td>
      test
    </td>
  </tr>
</table>