2016-09-05 2 views
-1
<div id="Page1"> 
    <p><strong><em>(*) 1) Page 1 Question 1</em></strong> 
    </p> 
</div> 
<br> 
<br> 


<div id="Checklist1B7"> 
    <table class="c1"> 
     <tr> 
      <td width="1%"><label class="c1"><input id="QUESTION1A1" name="S1A" type= 
      "checkbox"></label> 
      </td> 

      <td width="15%"> 
       <div class="c2"> 
        <label class="c4" for="QUESTION1A1">Strongly Disagree</label> 
       </div> 
      </td> 

      <td width="1%"><label class="c2"><input id="QUESTION1A2" name="S1B" type= 
      "checkbox"></label> 
      </td> 

      <td width="15%"> 
       <div class="c2"> 
        <label class="c5" for="QUESTION1A2">Disagree</label> 
       </div> 
      </td> 

      <td width="1%"><label class="c3"><input id="QUESTION1A3" name="S1C" type= 
      "checkbox"></label> 
      </td> 

      <td width="15%"> 
       <div class="c2"> 
        <label class="c6" for="QUESTION1A3">Undecided</label> 
       </div> 
      </td> 
     </tr> 


     <tr> 
      <td width="1%"><label class="c1"><input id="QUESTION1A4" name="S1D" type= 
      "checkbox"></label> 
      </td> 

      <td width="15%"> 
       <div class="c2"> 
        <label class="c4" for="QUESTION1A4">Agree</label> 
       </div> 
      </td> 

      <td width="1%"><label class="c2"><input id="QUESTION1A5" name="S1E" type= 
      "checkbox"></label> 
      </td> 

      <td width="15%"> 
       <div class="c2"> 
        <label class="c5" for="QUESTION1A5">Strongly Agree</label> 
       </div> 
      </td> 
     </tr> 
    </table> 
</div> 
<script type="text/javascript"> 
$(document).on("click", "input[type=checkbox]", function(e) { 
var num_checked = $("input[type=checkbox]:checked").length; 
if (num_checked > 2) { 
alert("sorry, you have already selected more than max !"); 
$(e.target).attr('checked',false); 
} 
}); 
</script> 

<p><strong><em>2) Page 1 Question 2</em></strong> 
</p> 
<br> 
<br> 


<div id="Checklist2B7"> 
    <table class="c1"> 
     <tr> 
      <td width="1%"><label class="c1"><input id="QUESTION2A1" name="S2A" type= 
      "checkbox"></label> 
      </td> 

      <td width="15%"> 
       <div class="c2"> 
        <label class="c4" for="QUESTION2A1">Monday</label> 
       </div> 
      </td> 

      <td width="1%"><label class="c2"><input id="QUESTION2A2" name="S2B" type= 
      "checkbox"></label> 
      </td> 

      <td width="15%"> 
       <div class="c2"> 
        <label class="c5" for="QUESTION2A2">Tuesday</label> 
       </div> 
      </td> 

      <td width="1%"><label class="c3"><input id="QUESTION2A3" name="S2C" type= 
      "checkbox"></label> 
      </td> 

      <td width="15%"> 
       <div class="c2"> 
        <label class="c6" for="QUESTION2A3">Wednesday</label> 
       </div> 
      </td> 
     </tr> 


     <tr> 
      <td width="1%"><label class="c1"><input id="QUESTION2A4" name="S2D" type= 
      "checkbox" value="4"></label> 
      </td> 

      <td width="15%"> 
       <div class="c2"> 
        <label class="c4" for="QUESTION2A4">Thursday</label> 
       </div> 
      </td> 

      <td width="1%"><label class="c2"><input id="QUESTION2A5" name="S2E" type= 
      "checkbox"></label> 
      </td> 

      <td width="15%"> 
       <div class="c2"> 
        <label class="c5" for="QUESTION2A5">Friday</label> 
       </div> 
      </td> 

      <td width="1%"><label class="c3"><input id="QUESTION2A6" name="S2F" type= 
      "checkbox"></label> 
      </td> 

      <td width="15%"> 
       <div class="c2"> 
        <label class="c6" for="QUESTION2A6">Saturday</label> 
       </div> 
      </td> 
     </tr> 


     <tr> 
      <td width="1%"><label class="c1"><input id="QUESTION2A7" name="S2G" type= 
      "checkbox" value="7"></label> 
      </td> 

      <td width="15%"> 
       <div class="c2"> 
        <label class="c4" for="QUESTION2A7">Sunday</label> 
       </div> 
      </td> 
     </tr> 
    </table> 
</div> 
<script type="text/javascript"> 
$(document).on("click", "input[type=checkbox]", function(e) { 
var num_checked = $("input[type=checkbox]:checked").length; 
if (num_checked > 4) { 
alert("sorry, you have already selected more than max !"); 
$(e.target).attr('checked',false); 
} 
}); 
</script> 

<table class="c2"> 
    <tr> 
     <td> 
      <div class="c5"> 
       <label class="c5"><button type="submit"><label class= 
       "c5">NEXT</label></button></label> 
      </div> 
     </td> 
    </tr> 
</table> 


<div class="c9"> 
    <label>1</label> 
</div> 


<p id="demo"> 
</p> 

3 개 이상의 체크 박스가 선택되어 있다면 첫 번째 질문의 체크 박스를 비활성화하고 작동하지만 내 문제는 다음과 같습니다. 동일한 페이지에서 모든 체크 박스를 선택하면 차단됩니다.하지만 질문 2에 대해 4 점 미만을 확인하십시오. 당신이 input[type=checkbox]을 대상으로하는 경우동일한 HTML에서 다른 확인란을 비활성화하는 방법은 무엇입니까?

+0

의 물론 나는 실제로 나는이 사이트를 이해하지 못한다. 나는 "도움이 필요하다"고 말했지만 모든 사람들이 먼저 나를 심문한다. –

+0

그럼 누가 나를 도와 주나요? –

+0

이해가 안되면 [도움]을 읽어야합니다. 모든 것이 여기에 설명되어 있습니다. 박사님, 우리는 정말로 당신을 돕기 위해 여기에 ** 있습니다 **, ** 이것은 ** 모든 사람들을 돕기위한 자원입니다 **. 귀하의 질의 응답은 귀하뿐만 아니라 여러 사람들에게 도움이 될 것으로 기대됩니다. – Liam

답변

-2

그것은 동일하게 각 질문에 내가 모든 체크 박스의 이름을 만든 그래서

는 DOM에있는 모든 체크 박스를 가리 킵니다

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml"> 
 

 
<head> 
 
    <meta name="generator" content="HTML Tidy for Linux (vers 25 March 2009), see www.w3.org" /> 
 
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-9" /> 
 
    <meta http-equiv="content-type" content="text/html; charset=windows-1254" /> 
 
    <meta http-equiv="content-type" content="text/html; charset=x-mac-turkish" /> 
 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
 
    <script src="https://code.jquery.com/jquery-1.11.1.min.js" type="text/javascript"></script> 
 
    <link rel="stylesheet" type="text/css" media="screen" href="/styles/_reset.css" /> 
 
    <link rel="stylesheet" type="text/css" media="screen" href="/styles/main3.css" /> 
 
</head> 
 

 
<body> 
 
    <br></br> 
 
    <br></br> 
 
    <br></br> 
 
    <br></br> 
 
    <br></br> 
 
    <br></br> 
 
    <div id="Page1"> 
 
     <p><strong><em>(*) 1) Page 1 Question 1</em></strong></p> 
 
    </div> 
 
    <br></br> 
 
    <br></br> 
 
    <div id="Checklist1B7"> 
 
     <table class="c1"> 
 
      <tr> 
 
       <td width="1%"> 
 
        <label class="c1"> 
 
         <input type="checkbox" name="S1" id="QUESTION1A1" /> 
 
        </label> 
 
       </td> 
 
       <td width="15%"> 
 
        <div class="c2"> 
 
         <label for="QUESTION1A1" class="c4"> 
 
          Strongly Disagree</label> 
 
        </div> 
 
       </td> 
 
       <td width="1%"> 
 
        <label class="c2"> 
 
         <input type="checkbox" name="S1" id="QUESTION1A2" /> 
 
        </label> 
 
       </td> 
 
       <td width="15%"> 
 
        <div class="c2"> 
 
         <label for="QUESTION1A2" class="c5"> 
 
          Disagree</label> 
 
        </div> 
 
       </td> 
 
       <td width="1%"> 
 
        <label class="c3"> 
 
         <input type="checkbox" name="S1" id="QUESTION1A3" /> 
 
        </label> 
 
       </td> 
 
       <td width="15%"> 
 
        <div class="c2"> 
 
         <label for="QUESTION1A3" class="c6"> 
 
          Undecided</label> 
 
        </div> 
 
       </td> 
 
      </tr> 
 
      <tr> 
 
       <td width="1%"> 
 
        <label class="c1"> 
 
         <input type="checkbox" name="S1" id="QUESTION1A4" /> 
 
        </label> 
 
       </td> 
 
       <td width="15%"> 
 
        <div class="c2"> 
 
         <label for="QUESTION1A4" class="c4"> 
 
          Agree</label> 
 
        </div> 
 
       </td> 
 
       <td width="1%"> 
 
        <label class="c2"> 
 
         <input type="checkbox" name="S1" id="QUESTION1A5" /> 
 
        </label> 
 
       </td> 
 
       <td width="15%"> 
 
        <div class="c2"> 
 
         <label for="QUESTION1A5" class="c5"> 
 
          Strongly Agree </label> 
 
        </div> 
 
       </td> 
 
      </tr> 
 
     </table> 
 
    </div> 
 
    <script type="text/javascript"> 
 
    $(document).on("click", "input[type=checkbox]", function(e) { 
 
     var QUS1 = $("input[name=S1]:checked").length; 
 
     if (QUS1 > 2) { 
 
      alert("sorry, you have already selected more than max !"); 
 
      $(e.target).attr('checked', false); 
 
     } 
 
     var QUS2 = $("input[name=S2]:checked").length; 
 
     if (QUS2 > 4) { 
 
      alert("sorry, you have already selected more than max !"); 
 
      $(e.target).attr('checked', false); 
 
     } 
 
    }); 
 
    </script> 
 
    <p><strong><em>2) Page 1 Question 2</em></strong></p> 
 
    </div> 
 
    <br></br> 
 
    <br></br> 
 
    <div id="Checklist2B7"> 
 
     <table class="c1"> 
 
      <tr> 
 
       <td width="1%"> 
 
        <label class="c1"> 
 
         <input type="checkbox" name="S2" id="QUESTION2A1" /> 
 
        </label> 
 
       </td> 
 
       <td width="15%"> 
 
        <div class="c2"> 
 
         <label for="QUESTION2A1" class="c4"> 
 
          Monday</label> 
 
        </div> 
 
       </td> 
 
       <td width="1%"> 
 
        <label class="c2"> 
 
         <input type="checkbox" name="S2" id="QUESTION2A2" /> 
 
        </label> 
 
       </td> 
 
       <td width="15%"> 
 
        <div class="c2"> 
 
         <label for="QUESTION2A2" class="c5"> 
 
          Tuesday</label> 
 
        </div> 
 
       </td> 
 
       <td width="1%"> 
 
        <label class="c3"> 
 
         <input type="checkbox" name="S2" id="QUESTION2A3" /> 
 
        </label> 
 
       </td> 
 
       <td width="15%"> 
 
        <div class="c2"> 
 
         <label for="QUESTION2A3" class="c6"> 
 
          Wednesday</label> 
 
        </div> 
 
       </td> 
 
      </tr> 
 
      <tr> 
 
       <td width="1%"> 
 
        <label class="c1"> 
 
         <input type="checkbox" name="S2" value="4" id="QUESTION2A4" /> 
 
        </label> 
 
       </td> 
 
       <td width="15%"> 
 
        <div class="c2"> 
 
         <label for="QUESTION2A4" class="c4"> 
 
          Thursday</label> 
 
        </div> 
 
       </td> 
 
       <td width="1%"> 
 
        <label class="c2"> 
 
         <input type="checkbox" name="S2" id="QUESTION2A5" /> 
 
        </label> 
 
       </td> 
 
       <td width="15%"> 
 
        <div class="c2"> 
 
         <label for="QUESTION2A5" class="c5"> 
 
          Friday</label> 
 
        </div> 
 
       </td> 
 
       <td width="1%"> 
 
        <label class="c3"> 
 
         <input type="checkbox" name="S2" id="QUESTION2A6" /> 
 
        </label> 
 
       </td> 
 
       <td width="15%"> 
 
        <div class="c2"> 
 
         <label for="QUESTION2A6" class="c6"> 
 
          Saturday</label> 
 
        </div> 
 
       </td> 
 
      </tr> 
 
      <tr> 
 
       <td width="1%"> 
 
        <label class="c1"> 
 
         <input type="checkbox" name="S2" value="7" id="QUESTION2A7" /> 
 
        </label> 
 
       </td> 
 
       <td width="15%"> 
 
        <div class="c2"> 
 
         <label for="QUESTION2A7" class="c4"> 
 
          Sunday</label> 
 
        </div> 
 
       </td> 
 
      </tr> 
 
     </table> 
 
    </div> 
 
    
 
    <table class="c2"> 
 
     <tr> 
 
      <td> 
 
       <div class="c5"> 
 
        <label class="c5"> 
 
         <button type="submit">NEXT 
 
         </button> 
 
        </label> 
 
       </div> 
 
      </td> 
 
     </tr> 
 
    </table> 
 
    <div class="c9"> 
 
     <label>1</label> 
 
    </div> 
 
    </form> 
 
    <p id="demo"></p> 
 
    </div> 
 
    </form> 
 
</body> 
 

 
</html>

관련 문제