How to add all input values using jquery
發表於 : 2017-12-19 20:44:29
https://stackoverflow.com/questions/707 ... ing-jquery
<input type="hidden" id="test_1" value="1">
....
<input type="hidden" id="test_10" value="10">
<input type="hidden" id="test_1" value="1">
....
<input type="hidden" id="test_10" value="10">
代碼: 選擇全部
val = 0;
$("input[id^='test_']").each(function() {
val = $(this).attr('value') + val;
});
console.log(val);