2017-01-25 2 views
0

をロードしていないとき、これは完全にコンソールで働いているコードです:jQueryのコンソールでの作業が、ウェブサイト

jQuery(".cf7_wrap_com li").each(function(){ 
     jQuery(this).find(".first_univer input").click(function(){ 
      var label1 = jQuery(this).parent().find("label").html();  
      if(jQuery(this).is(":checked")) { 
        jQuery(this).parent().find(".first_high").show(); 
         jQuery(".cf7_wrap_com li").not(jQuery(this).parent().parent()).each(function(){   
          jQuery(this).find(".first_high").hide();  
         }); 
          } 

      else {} 
      }); 
     }); 

、以下のコードは、私は私のカスタムのjsファイルに保存されているものですし、ウェブサイトの負荷

に取り組んでいません
jQuery(document).ready(function($){ 
    jQuery(window).bind("load", function() { 
    jQuery(".cf7_wrap_com li").each(function(){ 
     jQuery(this).find(".first_univer input").click(function(){ 
      var label1 = jQuery(this).parent().find("label").html();  
      if(jQuery(this).is(":checked")) { 
        jQuery(this).parent().find(".first_high").show(); 
         jQuery(".cf7_wrap_com li").not(jQuery(this).parent().parent()).each(function(){   
          jQuery(this).find(".first_high").hide();  
         }); 
          } 

      else {} 
      }); 
     }); 
    }); 
}); 

このコードをトリミングすることが可能かどうかを知りたければ、不要なものを追加した可能性もあります。

私は2つのラジオボタン(デフォルトでは非アクティブ)を使用しています。ユーザーがどちらかをクリックすると、短い形式が開きます。

ここでは画像です:

enter image description here

が、これはhtml次のとおりです。

<h1>What type of student?</h1> 
<ul class="cf7_wrap_com first_use"> 
<li> 
<div class="highschoolform first_univer"><input id="#school" name="School" type="radio" value="highschool" /> <label for="highschool">High School</label> 
<div class="cf7_wrap_hs first_high">[contact-form-7 id="3552" title="High school"]</div> 
</div> 
</li> 
<li> 
<div class="unversityform first_univer"><input id="#University" name="School" type="radio" value="University" /> <label for="University">University</label> 
<div class="cf7_wrap_uni first_high">[contact-form-7 id="3553" title="University"]</div> 
</div> 
</li> 
</ul> 
+0

あなたはデベロッパーコンソールですべてのエラーメッセージを取得していますか?あなたのHTMLは何ですか?jQueryを必要とするスクリプトの前にjQueryをロードしていますか? –

+0

私はちょうどHTMLを投稿しました。私はdevのエラーメッセージが表示されません。コンソール。スクリプト後にロード機能を追加するにはロード機能を追加してください(これは私が間違っているかもしれません) – Rahul

+0

jqueryが含まれていますか? –

答えて

1
最も近いと兄弟を使用
  • ラジオにクラスを与えます

    $(function() { 
     
        $(".school").on("click",function() { 
     
        $(this).closest("ul").find(".first_high").hide(); 
     
        $(this).siblings(".first_high").show(); 
     
        }); 
     
    });
    .first_high { display:none }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
     
    <h1>What type of student?</h1> 
     
    <ul class="cf7_wrap_com first_use"> 
     
        <li> 
     
        <div class="highschoolform first_univer"> 
     
         <input id="#school" class="school" name="School" type="radio" value="highschool" /> 
     
         <label for="highschool">High School</label> 
     
         <div class="cf7_wrap_hs first_high">[contact-form-7 id="3552" title="High school"]</div> 
     
        </div> 
     
        </li> 
     
        <li> 
     
        <div class="unversityform first_univer"> 
     
         <input id="#University" class="school" name="School" type="radio" value="University" /> 
     
         <label for="University">University</label> 
     
         <div class="cf7_wrap_uni first_high">[contact-form-7 id="3553" title="University"]</div> 
     
        </div> 
     
        </li> 
     
    </ul>

  • +0

    ラジオボタンがまだ機能していません。私はそれが私のページや何かの後に読み込まれていないが、把握できないスクリプトの問題だと思います。 http://i.imgur.com/ZnFz40t.gif – Rahul

    +0

    コンソールエラー? – mplungjan

    +0

    これは、エラーを表示せずにコンソールで完全に動作しています。私のjsファイルに保存した後にサイトをロードしても、エラーはありません – Rahul

    関連する問題