2016-05-20 7 views
0

「サービス」というページがあります。あなたがナビゲーションメニューからそのページに行くとき、私はサービスを表示したくない(それを説明するには複雑すぎる)。その後、私のインデックスページには、各タイプのサービスのリンクがあります。リンクをクリックすると、サービスページに移動し、そのサービスのみが表示されます。個々のサービスのリンクについてステートメントロジックが目的の結果を生成しない場合

、彼らは次のようになります。このシステムの作品の

<a href="serviceCheck2#service1">Service 1</a> 
<a href="serviceCheck2#service2">Service 2</a> 
<a href="serviceCheck2#service3">Service 3</a> 

この局面。サービスページに移動し、リンクからクリックしたサービスのみを表示します。

ナビゲーションメニューからサービスが表示されないか、サービスが表示されません。またはservice-display-boxです。現在、すべてのサービスが表示され、service-display-boxも同様です。

これを防ぐロジックを作成しようとしましたが、動作しません。下のjavascriptには、//addedのようなコメントが表示されます。これは、ブラウザにハッシュがある場合はservice-display-boxと特定のサービス項目を表示するロジックを作成しようと追加したものです。そうでなければservice-display-boxは表示されません。

私のロジックに何が問題なのですか?

$(function(){ 

    //get the section name from hash 
    var sectionName = window.location.hash.slice(1); 

    if (sectionName != null) { //added 
    //then show the section 
    $('#service-display-box').show(); 
    $(window.location.hash).show().scroll().siblings().hide(); 
    } else { //added 
     $('#service-display-box').hide(); //added 
    } //added 
}) 

#service-display-box { 
    display: none; 
} 
<div id="service-display-box"> 
     <div id="service-display-box-container"> 
     <div class="service-item-box" id="service1"> 
      <div class="service-item-title">1</div> 
      <h2 class="service-item-description"> Service</div> 
     </h2> 
     <h2 class="service-item-box" id="service2"> 
      <div class="service-item-title">2</div> 
      <div class="service-item-description"> Service</div> 
     </h2> 
     <h2 class="service-item-box" id="service3"> 
      <div class="service-item-title">3</div> 
      <div class="service-item-description"> Service</div> 
     </h2> 
     <h2 class="service-item-box" id="service4"> 
      <div class="service-item-title">4</div> 
      <div class="service-item-description"> Service</div> 
     </h2> 
     <h2 class="service-item-box" id="service5"> 
      <div class="service-item-title">5</div> 
      <div class="service-item-description"> Service/div> 
     </h2> 
     <h2 class="service-item-box" id="service6"> 
      <div class="service-item-title">6</div> 
      <div class="service-item-description"> Service</div> 
     </h2> 
     <div style="clear:both;"></div> 
     <div id="service-top"><span id="service-top-border">Back to all services</span></div> 
     </div> 
    </div> 

私もNULLと同じではありません空の文字列を返すwindow.location.hash.slice(1)

if (sectionName > 1) {

+0

あなたはPHPを使用していますか? – Ponilz

+0

@ C.oastいいえ、私はこれにjavascriptを使用しています。 – Becky

答えて

3

を試してみました。代わりに.length == 0を確認したいと思います。

+0

ありがとう!私はifとelseの順序を入れ替えましたが、それはやりました。再度、感謝します!! – Becky

関連する問題