jQuery:按类和输入类型选择 [英] jQuery: Selecting by class and input type

查看:58
本文介绍了jQuery:按类和输入类型选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用jQuery选择一组既具有某种输入类型(例如一个复选框)又具有某种类的元素.但是,当我尝试以下操作时:

I would like to select a set of elements that are both of a certain input type (say, a checkbox) and have a certain class using jQuery. However, when I try the following:

 $("input:checkbox .myClass")

我没有退回任何物品.如何在jQuery中完成此操作?

I don't get any items returned. How can I accomplish this in jQuery?

推荐答案

您的选择器正在查找具有.myClass类的复选框元素的任何后代.

Your selector is looking for any descendants of a checkbox element that have a class of .myClass.

尝试以下方法:

$("input.myClass:checkbox")

查看实际操作.

我也对此进行了测试:

$("input:checkbox.myClass")

它也将正常工作.以我的拙见,这种语法看起来确实很丑陋,因为大多数时候我希望:样式选择器排在最后.但是,正如我所说,任何一个都可以.

And it will also work properly. In my humble opinion this syntax really looks rather ugly, as most of the time I expect : style selectors to come last. As I said, though, either one will work.

这篇关于jQuery:按类和输入类型选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆