按值选择输入? [英] select an input by value?
问题描述
我在页面上有一堆隐藏的输入...
I have a bunch of hidden inputs on a page...
<input type='hidden' name='thing' value='' />;
<input type='hidden' name='thing' value='' />;
<input type='hidden' name='thing' value='' />;
等...
每次输入可以有任意值。
Each input can have an arbitrary value.
在jquery中,检查其中一个输入是否已设置为已知的特定值的最佳方法是什么?
In jquery, what is the best way to check if one of these inputs has been set to a known, specific value?
谢谢
推荐答案
如果您知道value属性设置为特定值你可以使用属性选择器
If you know that the value attribute is set to a specific value you can use the attribute selector
$('input[value="something"]');
http://api.jquery.com/category/selectors/
编辑添加:
您可能希望将attr选择器链接为输入[name =thing] [value =something]
并且@Drackir是对的,您可以通过匹配的 length
属性测试是否匹配一个或多个元素。
you may want to chain the attr selector as input[name="thing"][value="something"]
and @Drackir is right, you can test if it matches by whether one or more elements is in the set via the length
property of the match.
这篇关于按值选择输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!