admin管理员组文章数量:1336163
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='' />;
Etc...
Each input can have an arbitrary value.
In jquery, what is the best way to check if one of these inputs has been set to a known, specific value?
Thanks
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='' />;
Etc...
Each input can have an arbitrary value.
In jquery, what is the best way to check if one of these inputs has been set to a known, specific value?
Thanks
Share Improve this question edited Sep 24, 2015 at 7:26 moffeltje 4,6698 gold badges39 silver badges63 bronze badges asked Feb 22, 2011 at 21:49 travtrav 111 silver badge2 bronze badges3 Answers
Reset to default 4If you know that the value attribute is set to a specific value you can use the attribute selector
$('input[value="something"]');
http://api.jquery./category/selectors/
Edit to add:
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.
$('input[type="hidden"][value="5084405"]');
hope it helps
The following is what I'd suggest. You want to loop through all of the items with the name and check them and do something for each matching one.
$('input[name="thing"]').each(function() {
var itemValue = this.val();
if(itemValue == "X" || itemValue == "Y")
alert("Item value is " + itemValue);
});
本文标签: javascriptselect an input by valueStack Overflow
版权声明:本文标题:javascript - select an input by value? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742351812a2458644.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论