How can I select a hidden field by value?

泪湿孤枕 提交于 2019-12-20 16:23:09

问题


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

<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?


回答1:


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

$('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.




回答2:


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

E.g.

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

See also: jQuery 1.9.1 property selector




回答3:


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


来源:https://stackoverflow.com/questions/1065981/how-can-i-select-a-hidden-field-by-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!