質問編集履歴
3
質問の改善
    
        title	
    CHANGED
    
    | 
         
            File without changes
         
     | 
    
        body	
    CHANGED
    
    | 
         @@ -48,4 +48,7 @@ 
     | 
|
| 
       48 
48 
     | 
    
         
             
            条件を別に記述する方が良いのでしょうか?
         
     | 
| 
       49 
49 
     | 
    
         
             
            それとも別の方法がありますか?
         
     | 
| 
       50 
50 
     | 
    
         | 
| 
      
 51 
     | 
    
         
            +
            質問2の解答(エリア)をクリックした際に質問1を答えてなければ、エラー文を表示し、
         
     | 
| 
      
 52 
     | 
    
         
            +
            その後に質問1を答えた場合に、質問2のエラー文を非表示にしたいです。
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
       51 
54 
     | 
    
         
             
            どなたかご教示いただければ幸いです。
         
     | 
2
htmlの追記
    
        title	
    CHANGED
    
    | 
         
            File without changes
         
     | 
    
        body	
    CHANGED
    
    | 
         @@ -1,3 +1,23 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            ```html
         
     | 
| 
      
 2 
     | 
    
         
            +
            <div class="q1">
         
     | 
| 
      
 3 
     | 
    
         
            +
              <div class="q-num">質問1</div>
         
     | 
| 
      
 4 
     | 
    
         
            +
              <p class="q-txt">あなたは朝食で主に何を食べますか?</p>
         
     | 
| 
      
 5 
     | 
    
         
            +
              <ul>
         
     | 
| 
      
 6 
     | 
    
         
            +
                <li><label><input name="q1" type="checkbox">ごはん・パン</label></li>
         
     | 
| 
      
 7 
     | 
    
         
            +
                <li><label><input name="q1" type="checkbox">麺類</label></li>
         
     | 
| 
      
 8 
     | 
    
         
            +
                <li><label><input name="q1" type="checkbox">揚げ物</label></li>
         
     | 
| 
      
 9 
     | 
    
         
            +
              </ul>
         
     | 
| 
      
 10 
     | 
    
         
            +
            </div>
         
     | 
| 
      
 11 
     | 
    
         
            +
            <div class="q2">
         
     | 
| 
      
 12 
     | 
    
         
            +
              <div class="q-num">質問2</div>
         
     | 
| 
      
 13 
     | 
    
         
            +
              <p class="q-txt">運動は苦手ですか?</p>
         
     | 
| 
      
 14 
     | 
    
         
            +
              <div class="radio_btn">
         
     | 
| 
      
 15 
     | 
    
         
            +
                <input name="q2" type="radio" id="q2-1" disabled><label for="q2-1">Yes</label>
         
     | 
| 
      
 16 
     | 
    
         
            +
                <input name="q2" type="radio" id="q2-2" disabled><label for="q2-2">No</label>
         
     | 
| 
      
 17 
     | 
    
         
            +
              </div>
         
     | 
| 
      
 18 
     | 
    
         
            +
              <p class="error_txt1">質問1を選択してください。</p><!-- エラー文 --->
         
     | 
| 
      
 19 
     | 
    
         
            +
            </div>
         
     | 
| 
      
 20 
     | 
    
         
            +
            ```
         
     | 
| 
       1 
21 
     | 
    
         
             
            ```javascript
         
     | 
| 
       2 
22 
     | 
    
         
             
            $(function(){
         
     | 
| 
       3 
23 
     | 
    
         
             
              // 初期状態のボタンは無効
         
     | 
1
エラー表示させるスクリプトを追加
    
        title	
    CHANGED
    
    | 
         
            File without changes
         
     | 
    
        body	
    CHANGED
    
    | 
         @@ -14,6 +14,16 @@ 
     | 
|
| 
       14 
14 
     | 
    
         
             
                      $('input[name="q2"]').prop("disabled", true);
         
     | 
| 
       15 
15 
     | 
    
         
             
                    }
         
     | 
| 
       16 
16 
     | 
    
         
             
                });
         
     | 
| 
      
 17 
     | 
    
         
            +
                 $('.q2').click(function() {
         
     | 
| 
      
 18 
     | 
    
         
            +
                // q1のチェックされている数が0か0以下だったら
         
     | 
| 
      
 19 
     | 
    
         
            +
                if ($('input[name=q1]:checked').length >= 0) {
         
     | 
| 
      
 20 
     | 
    
         
            +
                  // エラー表示
         
     | 
| 
      
 21 
     | 
    
         
            +
                        $('.error_txt1').show();
         
     | 
| 
      
 22 
     | 
    
         
            +
                } else {
         
     | 
| 
      
 23 
     | 
    
         
            +
                  // エラー表示しない
         
     | 
| 
      
 24 
     | 
    
         
            +
                  $('error_txt1').hide();
         
     | 
| 
      
 25 
     | 
    
         
            +
                }
         
     | 
| 
      
 26 
     | 
    
         
            +
              });
         
     | 
| 
       17 
27 
     | 
    
         
             
            ```
         
     | 
| 
       18 
28 
     | 
    
         
             
            条件を別に記述する方が良いのでしょうか?
         
     | 
| 
       19 
29 
     | 
    
         
             
            それとも別の方法がありますか?
         
     |