如何通过值选择隐藏字段?

时间:2022-06-19 20:47:03

I have the following HTML generated by an ASP.NET repeater:

我有以下由ASP生成的HTML。网络中继器:

<table>
  <tr>
    <td><input type="hidden" name="ItemId" id="ItemId" value="3" /></td>
    <td>Terry</td>
    <td>Deleted</td>
    <td>Low</td>
    <td>Jun 21</td> 
  </tr>
  <!-- rows repeat -->
</table>

How do I select a particular hidden field by value, so that I can then manipulate the columns next to it?

如何按值选择一个特定的隐藏字段,以便操作它旁边的列?

3 个解决方案

#1


83  

Using jQuery Selectors, you can target your element by a certain attribute matching the desired value:

使用jQuery选择器,您可以通过匹配所需值的某个属性来定位您的元素:

$('input[value="Whatever"]');

This way you are targeting an input element, by the attribute value that is equal to the desired value.

这样,您的目标是输入元素,其属性值等于期望的值。

EDIT 5/14/2013: According to an answer below, this no longer works as of jQuery 1.9.

编辑5/14/2013:根据下面的答案,这不再适用于jQuery 1.9。

#2


10  

Note: Since jQuery 1.9 the input[value="banana"] selector is no longer valid, because 'value' of the input is technically not an attribute. You need to use the (far more difficult to read) .filter

注意:由于jQuery 1.9输入[value="banana"]选择器不再有效,因为输入的'value'在技术上不是属性。您需要使用(更难于阅读的).filter

E.g.

如。

$("input").filter(function () {
    return this.value === "banana";
});

See also: jQuery 1.9.1 property selector

参见:jQuery 1.9.1属性选择器

#3


8  

$('input:hidden[value=\'3\']');

#1


83  

Using jQuery Selectors, you can target your element by a certain attribute matching the desired value:

使用jQuery选择器,您可以通过匹配所需值的某个属性来定位您的元素:

$('input[value="Whatever"]');

This way you are targeting an input element, by the attribute value that is equal to the desired value.

这样,您的目标是输入元素,其属性值等于期望的值。

EDIT 5/14/2013: According to an answer below, this no longer works as of jQuery 1.9.

编辑5/14/2013:根据下面的答案,这不再适用于jQuery 1.9。

#2


10  

Note: Since jQuery 1.9 the input[value="banana"] selector is no longer valid, because 'value' of the input is technically not an attribute. You need to use the (far more difficult to read) .filter

注意:由于jQuery 1.9输入[value="banana"]选择器不再有效,因为输入的'value'在技术上不是属性。您需要使用(更难于阅读的).filter

E.g.

如。

$("input").filter(function () {
    return this.value === "banana";
});

See also: jQuery 1.9.1 property selector

参见:jQuery 1.9.1属性选择器

#3


8  

$('input:hidden[value=\'3\']');