2017-09-19 3 views
0

나는 여러 페이지 당 질문을했습니다. 문제는 내가 첫 번째 질문에 대답하면 두 번째 질문의 대답을 확인할 때 첫 번째 질문의 대답이 선택 취소되고 내 목표는 각 질문에 대해 단 하나의 대답 만있을 것이고 대답은 저장된다는 것입니다.여러 확인란에서 어떻게 하나의 답변을 저장 JQuery Mobile


당신의 jQuery 코드에서

$('input.answer').on('change', function() { 
 
    $('input.answer').not(this).prop('checked', false); 
 
$('input.answer').not(this).prop('checked', false).checkboxradio("refresh"); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> 
 
<script src="https://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script> 
 
<link href="https://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css" rel="stylesheet"/> 
 
<div class = "question">  
 
    
 
    
 
    <form> 
 
    <fieldset data-role="controlgroup"> 
 
     <legend for="0-0">my goal is having one answer per each question?to reporduce check three in first question and then check seven in second question , you would see the first question three would be unchecked which is not my desire</legend> 
 
     <label for="0-0-4">one</label> 
 
     <input class="answer answer-num-0" type="checkbox" name="0-0-4" id="0-0-4" value="4"> 
 
     <label for="0-0-3">two</label> 
 
     <input class="answer answer-num-0" type="checkbox" name="0-0-3" id="0-0-3" value="3"> 
 
     <label for="0-0-2">three</label> 
 
     <input class="answer answer-num-0" type="checkbox" name="0-0-2" id="0-0-2" value="2"> 
 
     <label for="0-0-1">four</label> 
 
     <input class="answer answer-num-0" type="checkbox" name="0-0-1" id="0-0-1" value="1"> 
 
     <label for="0-0-0">five</label> 
 
     <input class="answer answer-num-0" type="checkbox" name="0-0-0" id="0-0-0" value="0"> 
 
    </fieldset> 
 
    </form> 
 
    
 
    </div> 
 
      <div class="question"> 
 

 

 
     <form> 
 
    <fieldset data-role="controlgroup"> 
 
     <legend for="1-0">this is second question but when i check any answer from first question then check one of the answer of second question , first question's answer will be uncheck which is undesired.</legend> 
 
     <label for="0-1-4">six</label> 
 
     <input class="answer answer-num-1" type="checkbox" name="0-1-4" id="0-1-4" value="4"> 
 
     <label for="0-1-3">seven</label> 
 
     <input class="answer answer-num-1" type="checkbox" name="0-1-3" id="0-1-3" value="3"> 
 
     <label for="0-1-2">eight</label> 
 
     <input class="answer answer-num-1" type="checkbox" name="0-1-2" id="0-1-2" value="2"> 
 
     <label for="0-1-1">nine</label> 
 
     <input class="answer answer-num-1" type="checkbox" name="0-1-1" id="0-1-1" value="1"> 
 
     <label for="0-1-0">ten</label> 
 
     <input class="answer answer-num-1" type="checkbox" name="0-1-0" id="0-1-0" value="0"> 
 
    </fieldset> 
 
    </form> 
 
    </div> 
 
     <div class="question"> 
 
    <form> 
 
    <fieldset data-role="controlgroup"> 
 
     <legend for="1-1">to reporduce check three in first question and then check seven in second question , you would see the first question three would be unchecked which is not my desire</legend> 
 
    <label for="1-1-4">eleven</label> 
 
     <input class="answer answer-num-4" type="checkbox" name="1-1-4" id="1-1-4" value="4"> 
 
     <label for="1-1-3">twelve</label> 
 
     <input class="answer answer-num-4" type="checkbox" name="1-1-3" id="1-1-3" value="3"> 
 
     <label for="1-1-2">thirteen</label> 
 
     <input class="answer answer-num-4" type="checkbox" name="1-1-2" id="1-1-2" value="2"> 
 
     <label for="1-1-1">fourteen</label> 
 
     <input class="answer answer-num-4" type="checkbox" name="1-1-1" id="1-1-1" value="1"> 
 
     <label for="1-1-0">fifteen</label> 
 
     <input class="answer answer-num-4" type="checkbox" name="1-1-0" id="1-1-0" value="0"> 
 
    </fieldset> 
 
    </form> 
 
     </div>

답변

1

, 당신은 내가 그것을

도움이되기를 바랍니다

$('input.answer').on('change', function() { 

    $(this).closest('fieldset').find('input.answer').not(this).prop('checked',false).checkboxradio("refresh"); 

}); 

... 단지 선택된 체크 박스의 필드 셋 작업을 표시해야

+0

답변을 주셔서 감사합니다. 위의 코드를 사용하여 답변을 드리지는 못했습니다. 한 답변 만 할 수 있습니다. 각 질문마다 나는 첫 번째 질문에서 코드를 시험했다는 것을 의미합니다. 하나와 둘, 셋을 확인할 수 있습니다. 내 목표는 질문 당 단 하나의 대답만을 가지고 있습니다 ... – Jack

+0

https : //fiddle.jshell이 ​​필요합니다. net/rigobauer/tsfhbx6a /? 섹션 당 하나의 체크 박스 만 체크 할 수 있습니다. –

+0

jquery 모바일에서 작동하지 않습니다. 여기를 참조하십시오. https://jsfiddle.net/e26n3v0w/9/ – Jack