0

jqueryを使用して、別のページで特定のdivを表示/非表示にすることはできますか?

つまり、私たちが提供するさまざまなプランのコンテンツを表示するContent.aspxがあります。

detail.aspに、固有のdivを持つより詳細なページがあります。

<div id="detail-a">
     detailed content here for product A.
</div>

<div id="detail-b">
     detailed content here for product B.
</div>

表示非表示ボックスをスクロールして、ページの残りの詳細コンテンツを表示したくない...それがすべて理にかなっている場合...

4

3 に答える 3

1

これを正しく読んでいる場合、あるページのリンクでユーザーを 2 番目のページに移動させ、その 2 番目のページで、ユーザーが最初のページでクリックしたリンクに応じて特定の div を表示または非表示にする必要があります。

Contents.aspxについて

<a href="details.asp#detail-a">See Detail A</a>
<a href="details.asp#detail-b">See Detail B</a>

details.aspについて

<div id="detail-a">
  Data on Detail A
</div>
<div id="detail-b">
  Data on Detail B
</div>
<script type="text/javascript">
$( document ).ready( function(){
  /* If there is a Hash and the Hash is an ID on this page */
   if( document.location.hash && $( document.location.hash ) ) {
    /* Hide all the Detail DIVs */
     $( 'div[id^="detail-"]' ).not( document.location.hash ).hide();
    /* Show the Specified Detail DIV */
     $( document.location.hash ).show();
   }
} );
</script>
于 2010-05-22T03:11:23.403 に答える
0

div を display:none に設定できます。お気に入り:

$("#mydiv").css( "表示", "なし");

編集:私はこれを実際にテストしていませんが、各 div を display:none として開始し、新しいウィンドウへのリンクに mypage.htm/#detail1 のようなハッシュを追加することはできませんでした。

次に、ドキュメントのそのページで location.href を取得し、その要素の表示を上記のように設定します。

これは答えではなく、テストされていない提案です。これにはもっと洗練された解決策があるかもしれません。

于 2010-05-21T16:46:34.100 に答える
0

jQuery を使用して divを表示および非表示にするおよび/またはJQuery を使用して別の div の onClick イベントを表示および非表示にする の重複の可能性があります。

jquery で ID で要素を選択するのは $('#idname') であり、要素の表示/非表示は単純.show()です.hide()

$('#detail-a').show();
$('#detail-b').hide();

もちろん、いくつかのイベントトリガーに接続されています。

于 2010-05-21T16:50:50.647 に答える