How to select an input by value with jQuery 1.4.3 and higher

后端 未结 5 1457
星月不相逢
星月不相逢 2020-12-10 00:49

With jQuery 1.4.2 and many previous version it is possible to select inputs like this:

$(\'input[value=test]\')

But with 1.4.3 and higher t

5条回答
  •  庸人自扰
    2020-12-10 01:19

    As far as I can see, in newer jQuery versions, you can select INPUT elements by their "value" attribute, but not by the current .value property.

    When a value is changed by calling .val(), changing the native JS .value or also by direct user input, the HTML attribute is not changed. In former versions, selectors referred to the current value, while now they correctly refer to the HTML attribute.

    You can select however the current value with this code:

    $('input').filter(function() { return this.value == 'test' });
    

提交回复
热议问题