<input type="text" name="line" class="cntA1" value="1">
<input type="text" name="line" class="cntA2" value="2">
<input type="text" name="line" class="cntA3" value="3">
<input type="text" name="line" class="cntA4" value="4">
<input type="text" name="line" class="cntA2" value="2">
<input type="text" name="line" class="cntA3" value="3">
<input type="text" name="line" class="cntA4" value="4">
<a href="javascript:void(0);" onclick="cnt_plus();return false;">1 더하기</a>
<script type="text/javascript">
function cnt_plus() {
var cnt = $("input:text[name='line']").length;
for(var i=1; i<=cnt;i++) {
var scd = $(".cntA"+i).val();
var cc = parseInt(scd) + 1;
$(".cntA"+i).val(cc);
}
}
</script>
function cnt_plus() {
var cnt = $("input:text[name='line']").length;
for(var i=1; i<=cnt;i++) {
var scd = $(".cntA"+i).val();
var cc = parseInt(scd) + 1;
$(".cntA"+i).val(cc);
}
}
</script>
댓글 4개
11년 전
증가는 되지만 값을 사용하기에는 아니네요..
값을 사용하려면 그래도
class 값이 같으면 되잖아요..
값을 사용하려면 그래도
class 값이 같으면 되잖아요..
11년 전
제가 만든건 그냥 input 의value 값을 한번에 +1 시키는 방법입니다.
다른 좋은 방법있으시면 부탁드립ㄴ디ㅏ. ^^
다른 좋은 방법있으시면 부탁드립ㄴ디ㅏ. ^^
11년 전
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
</head>
<body>
<input type="text" name="line1" class="cntA1 line" value="1">
<input type="text" name="line2" class="cntA2 line" value="2">
<input type="text" name="line3" class="cntA3 line" value="3">
<input type="text" name="line4" class="cntA4 line" value="4">
<a href="javascript:void(0);" onclick="cnt_plus();return false;">1 더하기</a>
<script type="text/javascript">
function cnt_plus() {
var cnt = $(".line").length;
for(var i=1; i<=cnt;i++) {
var scd = $(".cntA"+i).val();
var cc = parseInt(scd) + 1;
$(".cntA"+i).val(cc);
}
}
</script>
</body>
</html>
이렇게 하면 4개 의 input 전달할여 사용할수 있습니다.
열매님의 소스를 조금 수정했습니다.^^
<html lang="en">
<head>
<meta charset="utf-8">
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
</head>
<body>
<input type="text" name="line1" class="cntA1 line" value="1">
<input type="text" name="line2" class="cntA2 line" value="2">
<input type="text" name="line3" class="cntA3 line" value="3">
<input type="text" name="line4" class="cntA4 line" value="4">
<a href="javascript:void(0);" onclick="cnt_plus();return false;">1 더하기</a>
<script type="text/javascript">
function cnt_plus() {
var cnt = $(".line").length;
for(var i=1; i<=cnt;i++) {
var scd = $(".cntA"+i).val();
var cc = parseInt(scd) + 1;
$(".cntA"+i).val(cc);
}
}
</script>
</body>
</html>
이렇게 하면 4개 의 input 전달할여 사용할수 있습니다.
열매님의 소스를 조금 수정했습니다.^^
11년 전
약간 다르게 해보자면 ^^
[code]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
</head>
<body>
<input type="text" name="line1" class="line" value="1">
<input type="text" name="line2" class="line" value="2">
<input type="text" name="line3" class="line" value="3">
<input type="text" name="line4" class="line" value="4">
<a href="#add_one" id="btn_add">1 더하기</a>
<script type="text/javascript">
$('#btn_add').click(function(evt) {
$('.line').each(function(idx, ele) {
$(ele).val(parseInt($(ele).val())+1);
});
evt.preventDefault();
});
</script>
</body>
</html>
[/code]
이왕 jquery 사용하는 김에.. 좀더 jquery 식으로 하면 이렇게도 할 수 있겠습니다
[code]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
</head>
<body>
<input type="text" name="line1" class="line" value="1">
<input type="text" name="line2" class="line" value="2">
<input type="text" name="line3" class="line" value="3">
<input type="text" name="line4" class="line" value="4">
<a href="#add_one" id="btn_add">1 더하기</a>
<script type="text/javascript">
$('#btn_add').click(function(evt) {
$('.line').each(function(idx, ele) {
$(ele).val(parseInt($(ele).val())+1);
});
evt.preventDefault();
});
</script>
</body>
</html>
[/code]
이왕 jquery 사용하는 김에.. 좀더 jquery 식으로 하면 이렇게도 할 수 있겠습니다
게시판 목록
팁게시판
디자인과 관련된 유용한 정보를 공유하세요.
질문은 상단의 QA에서 해주시기 바랍니다.
질문은 상단의 QA에서 해주시기 바랍니다.
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 5577 |
잘살아보자
|
11년 전 | 958 | |
| 5576 | 11년 전 | 1011 | ||
| 5575 |
잘살아보자
|
11년 전 | 1083 | |
| 5574 | 11년 전 | 808 | ||
| 5573 |
잘살아보자
|
11년 전 | 1839 | |
| 5572 |
잘살아보자
|
11년 전 | 3011 | |
| 5571 |
잘살아보자
|
11년 전 | 985 | |
| 5570 |
잘살아보자
|
11년 전 | 758 | |
| 5569 |
잘살아보자
|
11년 전 | 2696 | |
| 5568 | 11년 전 | 953 | ||
| 5567 | 11년 전 | 1414 | ||
| 5566 | 11년 전 | 825 | ||
| 5565 | 11년 전 | 1476 | ||
| 5564 |
잘살아보자
|
11년 전 | 1017 | |
| 5563 |
잘살아보자
|
11년 전 | 658 | |
| 5562 |
잘살아보자
|
11년 전 | 1259 | |
| 5561 |
잘살아보자
|
11년 전 | 1241 | |
| 5560 | 11년 전 | 902 | ||
| 5559 | 11년 전 | 1903 | ||
| 5558 | 11년 전 | 666 | ||
| 5557 | 11년 전 | 1077 | ||
| 5556 | 11년 전 | 1300 | ||
| 5555 | 11년 전 | 837 | ||
| 5554 | 11년 전 | 797 | ||
| 5553 | 11년 전 | 854 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기