键盘功能无法处理数据表搜索
16lz
2021-01-22
I have a fiddle for reference.
我有一个小提琴供参考。
I am trying to have keypress events work on the search textbox of the Database. Issue is, it's not working. I can't track what's wrong?
我试图让按键事件在数据库的搜索文本框中起作用。问题是,它不起作用。我无法追踪到底是什么问题?
The following code snippet seems not to be working.
以下代码段似乎无法正常工作。
if ($("#example_filter input").length > 0) {
alert("search exists");
}
$("#example_filter input").on("keyup", function() {
alert("hi");
});
3 个解决方案
#1
2
You need to first add DataTable
and then bind the events. Because at the time when you bind the keyup
event on input
, the input
was not present in the DOM
.
您需要先添加DataTable然后绑定事件。因为在输入时绑定keyup事件时,DOM中不存在输入。
$(document).ready(function() {
if ($("#example_filter input").length > 0) {
alert("search exists");
}
$("#example").DataTable();
$("#example_filter").on("keyup", 'input', function() {
alert("hi");
});
});
Demo
更多相关文章
- bootstrap,模态对话框,shown.bs.modal事件不会触发
- 更改html隐藏字段的事件
- JQuery 总结(3) jQuery 各种事件
- jQuery 选择器 与 事件
- jquery不会对select/选项更改事件作出反应。
- 绑定和解除相同javascript函数的目的是什么?
- 使用HTML5验证时如何绑定到提交事件?
- jquery自定义事件
- jQuery学习笔记- focus和blur事件妙用