jQuery input button click event listener(jQuery 输入按钮点击事件监听器)
问题描述
jQuery 的全新.我试图在我的页面上为以下控件设置事件侦听器,单击该控件时会显示警报:
Brand new to jQuery. I was trying to set up an event listener for the following control on my page which when clicked would display an alert:
<input type="button" id="filter" name="filter" value="Filter" />
但是没有用.
$("#filter").button().click(function(){...});
如何使用 jQuery 为输入按钮控件创建事件监听器?
How do you create an event listener for a input button control with jQuery?
推荐答案
首先,button()
是一个 jQuery ui 函数,用于创建 按钮小部件 与 jQuery 核心无关,它只是设置按钮的样式.
因此,如果您想使用小部件,请添加 jQuery ui 的 javascript 和 CSS 文件,或者删除它,如下所示:
First thing first, button()
is a jQuery ui function to create a button widget which has nothing to do with jQuery core, it just styles the button.
So if you want to use the widget add jQuery ui's javascript and CSS files or alternatively remove it, like this:
$("#filter").click(function(){
alert('clicked!');
});
另一件可能导致您出现问题的事情是,如果您没有等待输入呈现并在输入之前编写代码.jQuery 有 ready 函数,或者它的别名 $(func)
在 DOM 准备好后执行回调.
用法:
Another thing that might have caused you the problem is if you didn't wait for the input to be rendered and wrote the code before the input. jQuery has the ready function, or it's alias $(func)
which execute the callback once the DOM is ready.
Usage:
$(function(){
$("#filter").click(function(){
alert('clicked!');
});
});
所以即使订单是这样的,它也会起作用:
So even if the order is this it will work:
$(function(){
$("#filter").click(function(){
alert('clicked!');
});
});
<input type="button" id="filter" name="filter" value="Filter" />
演示
这篇关于jQuery 输入按钮点击事件监听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:jQuery 输入按钮点击事件监听器


基础教程推荐
- 如何在特定日期之前获取消息? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01