如何防止点击标题栏

时间:2017-12-18 02:31:14

标签: javascript jquery

如何防止标题列中的点击事件。

HTML:

<table>
   <tr>
      <th class="column">Header</th>
   </tr>
   <tr>
      <td class="column">Body 1</td>
   </tr>
   <tr>
      <td class="column">Body 2</td>
   </tr>
   <tr>
      <td class="column">Body 3</td>
   </tr>
</table>

我的剧本

$('.column:not("th")').on('click', function(){
    alert("test");
});

2 个答案:

答案 0 :(得分:5)

为什么不:

$('td.column').on('click', function(){
    alert("test");
});

答案 1 :(得分:0)

  1. 在代码上添加t选择器
  2. &#13;
    &#13;
    $('tbody .column').on('click', function() {
      alert("test");
    });
    &#13;
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <table>
      <thead>
        <tr>
          <th class="column">thead</th>
        </tr>
        <tr>
          <th class="column">thead Body 1</th>
        </tr>
        <tr>
          <th class="column">thead Body 2</th>
        </tr>
        <tr>
          <th class="column">thead Body 3</th>
        </tr>
      </thead>
    
      <tr>
        <td class="column">Header</td>
      </tr>
      <tr>
        <td class="column">Body 1</td>
      </tr>
      <tr>
        <td class="column">Body 2</td>
      </tr>
      <tr>
        <td class="column">Body 3</td>
      </tr>
    </table>
    &#13;
    &#13;
    &#13;