jQuery 显示/隐藏
我可以使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果我正确地阅读了这篇文章,您希望一个页面上的链接将用户发送到第二页,并在第二页上根据用户在第一页上单击的链接显示或隐藏特定的 div。
在Contents.aspx上
在details.asp上
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
On details.asp
可能重复 使用 jQuery 显示和隐藏 div 和/或 使用JQuery显示和隐藏不同div的onClick事件。
元素
在 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 elementsAttached to some event trigger of course.
您可以将 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.