0

How can I loop all input elements in JQuery and select only the inputs that the ID attribute ends in a specific name? For example see my html below:

My html is like this

<input type="text" id="a-user" value="0"/>
<input type="text" id="a-amount" value="10"/>
<input type="text" id="b-user" value="0"/>
<input type="text" id="b-amount" value="10"/>
......

I want to loop all the inputs that the id ends with -amount so that i can add a formatting to all those fields.

4

2 回答 2

2

像这样试试

$("input[id$=-amount]").each(function(){
    alert($(this).attr('id'));
});

查看演示
查看此文档以获取参考

于 2013-06-03T06:47:34.850 回答
1
$('[id$="someName"]').each(function() {
       // Your code here
});

use the $ symbol

Ends with Selector

于 2013-06-03T06:45:40.817 回答