按属性选择元素 [英] Select elements by attribute

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

问题描述

我复选框与生成的ID集合,他们中的一些有一个额外的属性。是否可以使用jQuery检查元素是否具有特定属性?
例如,我可以确认,如果下面的元素属性myattr?该属性的值可以变化。

I have a collection of checkboxes with generated ids and some of them have an extra attribute. Is it possible to use JQuery to check if an element has a specific attribute? For example, can I verify if the following element has the attribute "myattr"? The value of the attribute can vary.

<input type="checkbox" id="A" myattr="val_attr">A</input>

例如如何才能得到有不检查一个接一个此属性的所有复选框的集合?这可能吗?

For example how can I get a collection of all checkboxes that have this attribute without checking one by one? Is this possible?

推荐答案

你的意思是你可以选择他们?如果是这样,那么是:

Do you mean can you select them? If so, then yes:

$(":checkbox[myattr]")

这篇关于按属性选择元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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