jQuery在div中选择和过滤元素 [英] jQuery selecting and filtering elements inside a div
本文介绍了jQuery在div中选择和过滤元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在选择和过滤div中的元素时遇到问题。
I have a problem with selecting and filtering elements inside a div.
HTML:
<div id="wrapper">
<input type="text" value="you can edit me">
<input type="button" value="click me">
</div>
jQuery:
$("#wrapper").children().click(function() {
alert("hi there");
});
问题是每次点击div内的任何内容时都会收到提醒。 $ b但是我的要求是只有当用户点击按钮时才提醒。
我知道在jQuery中过滤元素是使用:button
The problem is I get alerted every time I click anything inside the div.
But my requirement is to alert only when the user clicks on the button.
I know that filtering the elements in jQuery is using :button
这是我试过的:
$("#wrapper").children(":button").click(function() {
alert("hi there");
});
和
$("#wrapper").children().filter(":button").click(function() {
alert("hi there");
});
无效
知道如何做到这一点?
推荐答案
$("#wrapper input[type=button]").click(function() {
alert("hi there");
});
这篇关于jQuery在div中选择和过滤元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文