我一直在研究一个网格控件,该控件使用 Datatables 的 KeyTable 插件。在这里和那里进行了一些调整,一切都很顺利,但是插件存在一个烦人的问题。以下是插件页面的示例代码:
$(document).ready( function () {
var keys = new KeyTable( {
"table": document.getElementById('example')
} );
/* Apply a return key event to each cell in the table */
keys.event.action( null, null, function (nCell) {
/* Block KeyTable from performing any events while jEditable is in edit mode */
keys.block = true;
/* Initialise the Editable instance for this table */
$(nCell).editable( function (sVal) {
/* Submit function (local only) - unblock KeyTable */
keys.block = false;
return sVal;
}, {
"onblur": 'submit',
"onreset": function(){
/* Unblock KeyTable, but only after this 'esc' key event has finished. Otherwise
* it will 'esc' KeyTable as well
*/
setTimeout( function () {keys.block = false;}, 0);
}
} );
/* Dispatch click event to go into edit mode - Saf 4 needs a timeout... */
setTimeout( function () { $(nCell).click(); }, 0 );
} );
} );
据我所知,在按下返回键之前,单元格不会“可编辑”,之后现在附加了一个点击事件。有没有办法让我在点击返回之前将点击事件(在我的情况下我想要一个 dblclick)附加到单元格?我尝试将函数绑定到“td.focus”和“example td”,但没有成功。我希望每个单元格都响应加载中的 dblclick,但也响应键。