Edit:由于您的元素是动态插入的,您必须使用delegated on()
,就像您的示例中一样,但您应该将其绑定到keydown事件,因为在IE中,keypress事件作为@Marc注释不会捕获非字符键:
$("#parentOfTextbox").on('keydown', '#textbox', function(e) {
var keyCode = e.keyCode || e.which;
if (keyCode == 9) {
e.preventDefault();
// call custom function here
}
});
判断一个示例here.