checkbox 관련

매출이 오르면 내리는 수수료! 지금 수수료센터에서 전자결제(PG)수수료 비교견적 신청해 보세요!
checkbox 관련

QA

checkbox 관련

본문

아래는 셀렉트시 내용이 보이고 안보이고 하는 소스인데요.

선택하는 셀렉트부분을 '체크박스'로 변경하고 싶은데 

 

체크박스로 변경할 경우 어떻게 처리해야 할까요?

 


<select name='wr_44' id='wr_44' >
<option value="">선택하세요.</option>
<option value="딸기" <?php echo ($write['wr_44'] == "딸기") ? "selected" : "";?>>딸기</option>
<option value="수박" <?php echo ($write['wr_44'] == "수박") ? "selected" : "";?>>수박</option>
</select>
 
<div class="estimate1" >
딸기
</div>
<div class="estimate2" >
수박
</div>
 
 
$("#wr_44").change(function(){
    if( $(this).val() == '딸기' ) {
        $(".estimate1").show();
        $(".estimate2").hide();
    }
    else{
        $(".estimate1").hide();
        $(".estimate2").show();
    } 
})
$("#wr_44").change(function(){
    if( $(this).val() == '수박' ) {
        $(".estimate1").hide();
        $(".estimate2").show();
    }
    else{
        $(".estimate1").show();
        $(".estimate2").hide();
    } 
})
$("#wr_44").trigger( 'change' );
 

이 질문에 댓글 쓰기 :

답변 1

<input type=checkbox name='wr_44' class='wr_44' show="estimate1" value="딸기" <?php echo ($write['wr_44'] == "딸기") ? "checked" : "";?>> 딸기 
<input type=checkbox name='wr_44' class='wr_44' show="estimate2" value="수박" <?php echo ($write['wr_44'] == "수박") ? "checked" : "";?>> 수박


<div class="estimate estimate1" >
딸기
</div>
<div class="estimate estimate2" >
수박
</div>
 
 <script>
$(".wr_44").click(function(){
    if( $(this).prop("checked") == true ) $("."+$(this).attr("show")).show();
    else $("."+$(this).attr("show")).hide();

    
})

 </script>


체크박스는 기본적으로 쌍으로 이루어진게 아니라서,
두개가 중복 선택 또는 둘다 선택해제도 될수 있는걸 원하시는거라면 위처럼 하시면 됩니다. 

답변을 작성하시기 전에 로그인 해주세요.
전체 2
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT