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

更多相关文章

  1. bootstrap,模态对话框,shown.bs.modal事件不会触发
  2. 更改html隐藏字段的事件
  3. JQuery 总结(3) jQuery 各种事件
  4. jQuery 选择器 与 事件
  5. jquery不会对select/选项更改事件作出反应。
  6. 绑定和解除相同javascript函数的目的是什么?
  7. 使用HTML5验证时如何绑定到提交事件?
  8. jquery自定义事件
  9. jQuery学习笔记- focus和blur事件妙用

随机推荐

  1. Android快速滚动
  2. androidmanifest.xml高级属性解析
  3. Intellij下的android实践
  4. android 创建文件夹失败
  5. Android平台上的JNI技术介绍
  6. Android通过startService播放背景音乐简
  7. Cordova+Vue整合到android studio上实现
  8. Android(安卓)Studio代码调试技巧篇
  9. android生命周期()
  10. 如何使Android应用程序获取系统权限