채택완료

체크 박스는 클릭박스 소스로 넣고 싶어요

2021-04-09 (금) 13:20:05 2,512

체크 박스를 클릭박스로 만들고 싶어요

하나는 체크 하면 기존에 체크된거는 풀리는것도요

맨처음에는 1000에 체크 되어 있고

5000에 체크 하면 처음 체크된 금액은 풀리고 5000에 체크 변경되게요

Copy
<input type='checkbox' name='' id='bet_point' value='1000' checked>1000
<input type='checkbox' name='' id='bet_point' value='5000'>5000
<input type='checkbox' name='' id='bet_point' value='10000' >10000
<input type='checkbox' name='' id='bet_point' value='30000'>30000
<input type='checkbox' name='' id='bet_point' value='50000' >50000
<input type='checkbox' name='' id='bet_point' value='100000'>100000
 
|

답변 3개 / 댓글 3개

채택된 답변
+20 포인트


1. id 를 class 로 바꾸고
 id='bet_point' ->  class='bet_point'

2. jquery 로 이벤트 처리를 해주세요.

$(".bet_point").click(function(){
    $(".bet_point").prop("checked", false);
    $(this).attr('checked', 'checked');
});

또는
$(".bet_point").click(function(){
    $(".bet_point").removeAttr('checked');
    $(this).attr('checked', 'checked');
});

답변에 대한 댓글 1개

2021-04-09 (금) 18:16:48
<button type='checkbox' name='' class='bet_point' value='1000' checked>1000</button>
<button type='checkbox' name='' class='bet_point' value='5000'>5000</button>
이렇게 바꾸면 박스클릭으로 되는건가요?

input type='radio' 사용하시면 될 것 같습니다

Copy
<input type="radio" id="apple" name="fruit" value="apple" checked>
<label for="apple">apple</label><br>
<input type="radio" id="banana" name="fruit" value="banana">
<label for="banana">banana</label><br>
<input type="radio" id="tomato" name="fruit" value="tomato">
<label for="tomato">tomato</label>

답변에 대한 댓글 2개

2021-04-09 (금) 14:06:48
id가 모두 동일해야 합니다.
2021-04-09 (금) 16:22:43
HTML 문법상 ID가 동일하면 에러로 봅니다
ID는 한페이지에 1개만 존재해야합니다
해당부분은 잘못된 생각이니 다른방법을 고려하세요

답변을 작성하려면 로그인이 필요합니다.