str*_*oir 26 javascript jquery filter css-selectors
我在选择和过滤div中的元素时遇到问题.
HTML:
<div id="wrapper">
<input type="text" value="you can edit me">
<input type="button" value="click me">
</div>
Run Code Online (Sandbox Code Playgroud)
jQuery:
$("#wrapper").children().click(function() {
alert("hi there");
});
Run Code Online (Sandbox Code Playgroud)
问题是我每次点击div内的任何内容时都会收到警报.
但我的要求是仅在用户点击按钮时发出警报.
我知道过滤jQuery中的元素正在使用:button
这是我尝试过的:
$("#wrapper").children(":button").click(function() {
alert("hi there");
});
Run Code Online (Sandbox Code Playgroud)
和
$("#wrapper").children().filter(":button").click(function() {
alert("hi there");
});
Run Code Online (Sandbox Code Playgroud)
它没用
有人知道怎么做吗?
Joh*_*ica 46
$("#wrapper input[type=button]").click(function() {
alert("hi there");
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
92129 次 |
| 最近记录: |