2013-06-03 40 views
0

如何循環JQuery中的所有輸入元素並只選擇ID屬性以特定名稱結尾的輸入?例如見下面我的html:通過輸入元素循環訪問ID結束於

我的HTML是這樣

<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"/> 
...... 

我想所有環路的ID與-amount這樣結束,我可以格式化添加到所有這些領域的投入。

回答

1
$('[id$="someName"]').each(function() { 
     // Your code here 
}); 

使用$符號

Ends with Selector