简体   繁体   English

dataTable可编辑单元格不响应双击事件

[英]dataTable editable cell not responding to double click event

I have a dataTable defined as 我有一个dataTable定义为

<table id="table1"></table>

$('#table1').dataTable({
    /*definition goes here*/
});

The table is currently editable using the KeyTables plugin. 该表当前可以使用KeyTables插件进行编辑。

However, I want to make it editable on double click 但是,我想使其双击可编辑

I tried 我试过了

$('#table1 tbody tr td').dblclick(function(){
    var e = jQuery.Event('keypress');
    e.keyCode = 13;
    e.which = 13;
    $(this).trigger(e);
});

However, this does not trigger the enter key event on the dataTable cell. 但是,这不会触发dataTable单元上的Enter键事件。

Well the tr in the table generated dynamically so it won't get the event binding that way, so you could use event delegation with the use of .on() method: 那么表中的tr是动态生成的,因此它不会以这种方式获取事件绑定,因此可以将event delegation.on()方法配合使用:

$('#table1').on('dblclick', 'td', function(){

This is a specific syntax for delegating the event to the closest static parent. 这是用于将事件委派给最接近的静态父代的特定语法。

$(staticParent).on(event, selector, callback);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM