jQuery 显示/隐藏

发布于 2024-09-02 20:36:44 字数 375 浏览 2 评论 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>

我不希望显示隐藏框滚动以显示页面其余部分的详细内容... 如果这一切都有意义的话……

Can i user jquery to show / hide a specific div on another page?

i.e. i have Content.aspx that shows content for different plans we offer.

on detail.asp i have a more detailed page that hase unique divs.

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

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

i dont want the show hide box to scroll to show the rest of the page detailed content...
if that all makes sense...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

灯下孤影 2024-09-09 20:36:44

如果我正确地阅读了这篇文章,您希望一个页面上的链接将用户发送到第二页,并在第二页上根据用户在第一页上单击的链接显示或隐藏特定的 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>

If I am reading this correctly, you are wanting links on one page to send the user to a second page and, on that second page, show or hide specific divs dependent on which link the user clicked on the first page.

On Contents.aspx

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

On 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>
寂寞陪衬 2024-09-09 20:36:44

可能重复 使用 jQuery 显示和隐藏 div 和/或 使用JQuery显示和隐藏不同div的onClick事件

元素

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

在 jquery 中通过 ID 选择元素是 $('#idname') ,显示/隐藏只是 .show().hide() 所以对于附加到的 当然是一些事件触发。

Possible duplicate of Showing and hiding a div with jQuery and/or Using JQuery to show and hide different div's onClick event.

Selecting an element by ID in jquery is $('#idname') and show/hide are simply .show() and .hide() so for your elements

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

Attached to some event trigger of course.

罪#恶を代价 2024-09-09 20:36:44

您可以将 div 设置为 display:none。
比如:

$("#mydiv").css("display", "none");

编辑:
我还没有真正测试过这一点,但是您不能将每个 div 启动为 display:none 并在新窗口的链接上添加一个哈希值,例如:mypage.htm/#detail1。

然后在文档准备好的页面中获取 location.href 并按照上面的详细说明设置该元素的显示。

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

You can set the div to display:none.
Like:

$("#mydiv").css( "display", "none");

EDIT:
I haven't really tested this, but couldn't you just start each div as display:none and on your link to the new window add a hash like: mypage.htm/#detail1.

then in that page on document ready get the location.href and set the display for that element back as detailed above.

This isn't an answer, just an untested suggestion. There may very well be a more elegant solution to this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文