jquery选择器如何选择两个元素
<select name="d1">
<option value="dd">111</option>
<option value="dd">111111</option>
</select>
<select name="d2">
<option value="dd">2222</option>
<option value="dd">222222222222</option>
</select>
我有两个选择如何使用jquery选择这两个
$("select[name='d1']").change(function(){xxx});
这个代码只能选择一个元素,任何人都可以帮忙,谢谢
<select name="d1">
<option value="dd">111</option>
<option value="dd">111111</option>
</select>
<select name="d2">
<option value="dd">2222</option>
<option value="dd">222222222222</option>
</select>
i have two select how two use jquery select this two
$("select[name='d1']").change(function(){xxx});
this code only could select one element,any one could give a hand,thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
有几种选择。
选择页面上的所有选择元素:
仅选择 ID 为
formD
的表单中包含的那些选择元素:仅选择
d
类中的那些选择元素(添加每个选择元素的class
HTML 属性):仅选择那些 select 元素其姓名/ID 以
d
开头:仅选择那些由 ID 特别命名的选择元素(添加一个
id 每个选择元素的 HTML 属性):
仅选择那些使用
特别命名的选择元素>name
属性(我会尽量避免,因为它的可读性较差):There are several options.
Select all select elements on the page:
Select only those select elements contained within a form having the ID
formD
:Select only those select elements in class
d
(add aclass
HTML attribute to each select element):Select only those select elements whose names/IDs begin with
d
:Select only those select elements specifically named by ID (add an
id
HTML attribute to each select element):Select only those select elements specifically named using the
name
attribute (which I would try to avoid because it is less readable):您可以选择 d1 或 d2:
但如果您为它们分配相同的类,然后根据该类进行选择,则会更优雅:
You could select d1 or d2:
But it would be more elegant if you assigned them the same class and then selected based on that:
$("select[name^=d]")
- 将返回名称以d
开头的所有select
。这是小提琴: http://jsfiddle.net/KjURE/ 。这正是您所要求的$("select[name^=d]")
- will return allselect
s with name beginning ind
. Here is the fiddle: http://jsfiddle.net/KjURE/ . This is exactly what you asked for