单击链接重新打开关闭后的 div
我有 jquery 隐藏链接。我拥有它,以便用户可以单击关闭下面链接列表的按钮。这使得它下面的另一个列表向上移动。
现在的问题是,当用户单击链接时,关闭的 div 会再次打开。
有没有办法保存div的状态?因此,如果它已关闭,请在用户单击链接时保持其关闭。
谢谢,刚开始学习jquery。这是我的代码:
$(document).ready(function() {
$("#menu_toggle a").click(function() {
$("#menu_toggle a").toggle();
if($('#secondary').is(':visible')) {
$("#secondary").slideUp("slow");
stop(true,true);
} else {
$("#secondary").slideDown("slow");
stop(true,true);
}
});
$("#admin_toggle a").click(function() {
$("#admin_toggle a").toggle();
if($('#admin').is(':visible')) {
$("#admin").slideUp("slow");
stop(true,true);
} else {
$("#admin").slideDown("slow");
stop(true,true);
}
});
});
这里是 jfiddle
现在,当我单击带有 # 属性的链接对其进行 href 时不执行任何操作,但在我的本地服务器上执行此操作。
I have jquery hiding links. I have it so the user can click on the button which closes the list of links underneath. Which makes another list underneath it move up.
Now problem is, when the user clicks on a link, the div that was closed is opened up again.
Is there way to save the state of the div? So if it's closed, keep it closed if the user clicks on a link.
Thanks, just started learning jquery. Here is my code:
$(document).ready(function() {
$("#menu_toggle a").click(function() {
$("#menu_toggle a").toggle();
if($('#secondary').is(':visible')) {
$("#secondary").slideUp("slow");
stop(true,true);
} else {
$("#secondary").slideDown("slow");
stop(true,true);
}
});
$("#admin_toggle a").click(function() {
$("#admin_toggle a").toggle();
if($('#admin').is(':visible')) {
$("#admin").slideUp("slow");
stop(true,true);
} else {
$("#admin").slideDown("slow");
stop(true,true);
}
});
});
here it is on jfiddle
now it when I click on the links with # attribute to href it doesn't do anything but on my local server it does.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
链接指向哪里?这些链接是否附加了任何事件,例如 onclick 或 onhashchange?如果是这样,请也发布这些事件处理程序。
jsfiddle 代码中的所有链接都指向“#”,这显然没有任何作用。这与您的实际代码相同吗?还是链接指向其他页面?如果单击其中一个链接导致浏览器刷新当前页面或导航到另一页面,则加载新页面时菜单会自行重置也就不足为奇了。您必须使用 cookie 或某种服务器端脚本来记住不同页面视图中的菜单状态。
Where do the links point to? Are there any events attached to those links, such as onclick or onhashchange? If so, please post those event handlers as well.
All the links in your jsfiddle code point to "#", which obviously doesn't do anything. Is that the same with your actual code, or do the links point to other pages? If clicking on one of those links causes the browser to refresh the current page or navigate to another page, it's no surprise that the menus reset themselves when the new page is loaded. You'll have to use a cookie or some sort of server-side scripting to remember the state of the menu across different page views.