如何禁用单元格表格中的单击事件?

时间:2017-08-07 10:09:15

标签: javascript jquery html html-table

我有html表,我想使用jQuery或JavaScript在表(th, td, tr)的任何单元格中禁用click事件。我该怎么做?



<table id="table1" border="1px">
<tr>
  <th>Title1</th>
  <td>Orange</td>
  <th>Title2</th>
  <td>Apple</td>
</tr>
<tr>
  <th>Title3</th>
  <td>Food</td>
  <th>Title4</th>
  <td>Fish</td>
</tr>
</table>
&#13;
&#13;
&#13;

3 个答案:

答案 0 :(得分:0)

如果通过禁用click事件表示禁用事件侦听器,则尝试使用off方法:

&#13;
&#13;
$(document).ready(function(){
  $('#disable-button').on('click',function(){
    $('#table1').off('click');
  });
  
  $('#table1').on('click',function(){
      alert('click event happened');
  });
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id="table1" border="1px">
<tr>
  <th>Title1</th>
  <td>Orange</td>
  <th>Title2</th>
  <td>Apple</td>
</tr>
<tr>
  <th>Title3</th>
  <td>Food</td>
  <th>Title4</th>
  <td>Fish</td>
</tr>
</table>

<button id="disable-button">Disable listener</button>
&#13;
&#13;
&#13;

否则,一个非常简单的方法是使用纯CSS:

pointer-events:none

但是因为你想在jquery中这样做:

如果你正在使用jQuery版本1.4.3 +:

$('selector').click(false);

如果不是:

$('selector').click(function(){ return false; });

答案 1 :(得分:0)

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);


        if ((requestCode == GALLERY_INTENT_TIME_TABLE || requestCode == GALLERY_INTENT_EXAM) && resultCode == RESULT_OK) {

            if(requestCode == GALLERY_INTENT_TIME_TABLE) {
                //do timetable operation
            } else if(requestCode == GALLERY_INTENT_EXAM) {
                //do exam operation
            }

        }
    }

答案 2 :(得分:0)

嗯,afaik,你没有在代码中注册任何点击事件,所以它被认为好像你没有。 此外,@ RoryMcCrossan还说鼠标没有显示任何事件。或cursor:default表示正常光标图标(箭头)

相关问题