简体   繁体   English

动态清除表行并向其中添加新的行集后,Keydown事件在IE和Chrome中不起作用! (适用于Firefox)

[英]Keydown event is not working in IE and Chrome after dynamically clearing table row and adding new set of row to it !!! (Its working in Firefox)

I am trying to implement navigation in array through arrow keys. 我正在尝试通过箭头键在数组中实现导航。 I got is working by following code. 我正在通过以下代码工作。

"onLoad": function () {
        $('#tbl tbody').attr("tabindex", 1);
        $('#tbl tbody').keydown(function (event) {
            // Code for navigation to next or previous in table
        });
    },

Key down event is working fine on page load, just i need to click on table once and i am able to navigate through arrow key. 按键事件在页面加载时工作正常,只需要单击一次表即可浏览箭头键。 But I am facing problem after clearing table dynamically and adding new set of rows to it.At end of table i need to make call back to server which is clearing this table rows and adding new sets of row to is. 但是在动态清除表并向其中添加新的行集之后,我面临着问题。在表的末尾,我需要回叫服务器以清除表中的行并将新的行集添加到is。 now after that Keydown event is not working. 现在,该Keydown事件不起作用。 I need to click on table again to navigate. 我需要再次单击表格进行导航。 Note: This is happening only on IE and Crome. 注意:这仅在IE和Cr​​ome上发生。 On firefox it is working fine and i am able to navigate on new set of data or rows. 在Firefox上,它工作正常,我能够浏览新的数据或行集。

Bind it with jQuery's live function. 将其与jQuery的live函数绑定。

$('#tbl tbody').live('keydown', function(e) {});

This applies the callback to elements created at run time as well. 这也将回调应用于在运行时创建的元素。

Documentation 文献资料

It working for me now as suggested by jerome.s. jerome.s建议,它现在对我有用。

now what i am doing, i am setting focus when Ajax call complete and its call back function also done with its job to re-render table. 现在我在做什么,我将在Ajax调用完成时设置焦点,并且其回调函数也需要完成其工作以重新呈现表。 when rendering part complete i have set focus to table body. 当渲染零件完成时,我将焦点放在了表主体上。

$('#tbl body').focus();

Thanks for your responses. 感谢您的回复。

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

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