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

如果我阅读正确,您希望一个页面上的链接将用户发送到第二个页面,并在第二个页面上显示或隐藏特定的 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("display", "none");

编辑:我还没有真正测试过这个,但是你不能把每个 div 都作为 display:none 开始,然后在指向新窗口的链接上添加一个哈希,比如:mypage.htm/#detail1。

然后在文档准备好的该页面中获取 location.href 并将该元素的显示设置回如上所述。

这不是一个答案,只是一个未经测试的建议。很可能有一个更优雅的解决方案。

于 2010-05-21T16:46:34.100 回答
0

Showing and hide a div with jQuery and/or Using JQuery to show and hide different div's onClick event 的可能重复项。

在 jquery 中按 ID 选择元素是 $('#idname') 并且显示/隐藏很简单.show().hide()因此对于您的元素

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

当然附加到一些事件触发器。

于 2010-05-21T16:50:50.647 回答