2014-03-31 3 views
0
$(document).ready(function() { 
    $('#bundlesubmit').click(function() { 

if ($("#three").is(':checked')) { 
     $("#bundleDropDown1").toggle(); 
     alert ('hey this is the three only one'); 
} 
if ($("#two").is(':checked')) { 
     $("#bundleDropDown2").toggle(); 
     alert ('hey this is the second one'); 
} 
if ($("#two").is(':checked') == true && $("#three").is(':checked') == true) { 
     $("#bundleDropDown").toggle(); 
     alert ('hey this is the two options'); 

} 
    }); 
    }); 

그래서 인터넷을 통해 답변을 검색했지만 아무 것도 찾을 수 없었습니다! 코드가 작동하지만 사람이 두 개의 확인란을 선택하면 해당 기능을 수행하고 단일 확인란의 기능을 수행합니다.표시 확인란을 선택한 특정 확인란 JQUERY

#TWO 및 #THREE를 선택하면 모든 기능을 수행합니다. 두 항목 모두 하나의 기능 만 실행하도록 선택되었는지 어떻게 알 수 있습니까?

+0

당신의 관련 HTML 구조는 무엇입니까? –

답변

0

당신은 다른 구조를

$(document).ready(function() { 
    $('#bundlesubmit').click(function() { 

    if ($("#two").is(':checked') == true && $("#three").is(':checked') == true) { 
     $("#bundleDropDown").toggle(); 
     alert ('hey this is the two options'); 

    } 
    else if ($("#three").is(':checked')) { 
     $("#bundleDropDown1").toggle(); 
     alert ('hey this is the three only one'); 
    } 
    else if ($("#two").is(':checked')) { 
     $("#bundleDropDown2").toggle(); 
     alert ('hey this is the second one'); 
    } 

    }); 
}); 

편집이 필요 - div의를

$(document).ready(function() { 
    $('#bundlesubmit').click(function() { 
     $(".bundledivs").hide(); 
     if ($("#two").is(':checked') && $("#three").is(':checked')) { 
      $("#bundleDropDown").show(); 
     } else if ($("#three").is(':checked')) { 
      $("#bundleDropDown1").show(); 
     } else if ($("#two").is(':checked')) { 
      $("#bundleDropDown2").show(); 
     } 
    }); 
}); 
jQuery를

HTML

<label for="two">Two 
    <input type="checkbox" id="two" /> 
</label> 
<label for="three">Three 
    <input type="checkbox" id="three" /> 
</label> 
<button id="bundlesubmit">Bundle Submit</button> 
<div id="bundleDropDown" class="bundledivs">Bundle Drop Down</div> 
<div id="bundleDropDown1" class="bundledivs">Bundle Drop Down 1</div> 
<div id="bundleDropDown2" class="bundledivs">Bundle Drop Down 2</div> 

(나는 당신이 필요로 변경하는 간단한 구조를 가정) 숨길

CSS

.bundledivs { 
    display:none; 
} 

바이올린 : http://jsfiddle.net/JyG9Q/

+0

나는 동의한다. ... 첫번째 것을위한 수표는, 첫째로 일 필요가있다 – pj013

+0

그것은 잘 작동하는 것을 보인다. 나는 기본적으로 3 개의 체크 박스를 가지고 있으며 선택에 따라 새로운 div가 열릴 것입니다. 그럼 지금 그들이 선택하고 다시 선택하면, 그것은 여전히 ​​오래된 것들을 보여줍니다 ??? – itssamduh

+0

@itssamduh - 업데이트 된 답변보기 –

관련 문제