I want to get all numbers in javascript and i write this.
THIS
<c:forEach items="${boardList}" var="board">
<tr>
<td><input type="hidden" class="boardNum" value="${board.num}">${board.num}
</td> << here!!!!
<td><a class="boardTitle"
style="color: rgb(0, 100, 0);" >${board.title}</a></td>
<td>${board.writer}</td>
<td><f:formatDate value="${board.writeDate}" pattern="yy.MM.dd" /></td>
</tr>
</c:forEach>
<script>
var num = $(".boardNum").val();
var title= $(".boardTitle");
title.click(function(){
alert(num); >> only one number.
</script>
i want all numbers.ex) board board.num(1~20) but these codes in javascript is only one number (ex) num 20).
i think it will be using clouser but i dont know where to write clouser.
if what i think is not resolved, what do i do
ps) english is not good.
var num = $(".boardNum").val();
Your current code fetches all elements having class as boardNum
, however .val()
will return value only for one element.
Assuming that you need all board numbers from hidden fields.
var boardNums = $(this).parents('table').find('input[type=hidden].boardNum').map(function(){return this.value;}).get();
console.log('all nums',boardNums);
OR
var boardNums = $('input[type=hidden].boardNum').map(function(){return this.value;}).get();
console.log('all nums',boardNums);
Iterate over a jQuery object, executing a function for each matched element. https://api.jquery.com/each/
var num = $(".boardNum");
num.each(function( index ) {
console.log( index + ": " + $( this ).val() );
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.