「サービス」というページがあります。あなたがナビゲーションメニューからそのページに行くとき、私はサービスを表示したくない(それを説明するには複雑すぎる)。その後、私のインデックスページには、各タイプのサービスのリンクがあります。リンクをクリックすると、サービスページに移動し、そのサービスのみが表示されます。個々のサービスのリンクについてステートメントロジックが目的の結果を生成しない場合
、彼らは次のようになります。このシステムの作品の
<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) {
あなたはPHPを使用していますか? – Ponilz
@ C.oastいいえ、私はこれにjavascriptを使用しています。 – Becky