2016-09-05 27 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>