javaScript&jQurey
동일한 input name 값 가져오기
jeongyj
2021. 10. 21. 11:09
<script>
$(document).ready( function() {
// for 문으로 가져 올 경우
$("#BtnFor").click(function(){
var size = $("input[name='EMAIL']").length;
for(i=0;i<size;i++){
alert( i + "번째 메일주소 : " + $("input[name='EMAIL']").eq(i).attr("value") );
}
});
// each 로 가져올 경우
$("#BtnEach").click(function(){
$("input[name='EMAIL']").each(function (i) {
alert( i + "번째 메일주소 : " + $("input[name='EMAIL']").eq(i).attr("value") );
});
});
});
</script>
<body>
<tr>
<td><input type="text" name="EMAIL" id="EMAIL" value="" ></td>
<td><input type="text" name="EMAIL" id="EMAIL" value="" ></td>
<td><input type="text" name="EMAIL" id="EMAIL" value="" ></td>
</tr>
<tr>
<button id="BtnFor"> 버튼FOR </button>
<button id="BtnEach"> 버튼EACH </button>
</tr>
</body>
동일한 NAME이 여러개 생성될 때 참조 하시면 됩니다.
출처: https://choija.tistory.com/63 [수캥이의 삶 ]