jQuery的输入按钮点击事件监听器

编程入门 行业动态 更新时间:2024-10-26 17:23:44
本文介绍了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?

推荐答案

第一件事,第一,按钮()是一个jQuery UI函数来创建的button窗口小部件这无关与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!'); });

这可能造成你的问题的另一件事是,如果你没有等待输入被渲染和输入以前写的code。 jQuery的拥有的 功能齐全 的,或者它的别名 $(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" />

DEMO

更多推荐

jQuery的输入按钮点击事件监听器

本文发布于:2023-08-01 18:44:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1270741.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:监听器   按钮   事件   jQuery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!