我在 keyup 事件上使用以下函数重定向到另一个 javascript 函数。问题是它似乎没有触发,尽管它确实将函数绑定到文本框。
$(document).ready(function () {
EnablePickTargetButton();
//clear contents; use a delay because tinyMCE editor isn't always fully loaded on document.ready
var t = setTimeout(function () {
if (typeof textEditorForCreate != 'undefined' && tinymce.editors.length > 0)
tinyMCE.activeEditor.setContent('');
}, 300);
var txtSearchUser = $('#txtSearchUser');
if(typeof txtSearchUser != 'undefined')
{
$('#txtSearchUser').keyup(function (e) {
if (e.keyCode == 13) {
e.preventDefault();
searchUser();
}
else
alert('cucu');
});
}
});
Run Code Online (Sandbox Code Playgroud)
甚至没有出现警报。检查 html,我可以看到它没有将 onkeyup 添加到文本框;文本框位于窗体上 div 中托管的弹出窗口中;但是在 document.ready 上它运行该函数没有错误。
在文档或最近的静态元素上试试这个委托。(如果元素是动态添加的)
$(document).on('keyup','#txtSearchUser',function(){
//Code
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5546 次 |
| 最近记录: |