简体   繁体   English

如何在jQuery中查找元素值

[英]How to find element value in jQuery

I am trying to get all class call Position $(".Position") and get then find the value that == 4 and then show the id. 我试图让所有类都调用Position $(“。Position”),然后找到== 4的值,然后显示id。

<input type="Text" id="#34" value="1" class="Position">
<input type="Text" id="#22" value="2" class="Position">
<input type="Text" id="#37" value="3" class="Position">
<input type="Text" id="#41" value="4" class="Position">

Thanks 谢谢

使用属性等于选择器

alert($("input.Position[value='4']").attr("id"));

First, you have to take off the '#' from your id's. 首先,您必须从ID中删除“#”。

<input type="Text" id="34" value="1" class="Position">

Then you can find the input you are looking for with the following selector: 然后,可以使用以下选择器找到所需的输入:

$('input.Position[value=4]').attr('id')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM