Jquery 菜单点击问题
我的网站顶部有两个选项卡,分别为“企业”和“个人”。当页面首次加载时,“业务”选项卡的项目将显示在选项卡下方的栏中。通过单击“个人”,它会显示个人项目。这对我来说效果很好。现在我想更改代码中的某些内容,当我单击任何个人菜单项时,页面会刷新,并再次显示业务菜单项。 看看这里的 网站 这
是我的 Jquery 代码:
$(document).ready(function() {
$('.business-tab').show();
$('.personal-tab').hide();
$('.business-tab #block-nice_menus-2').hide();
$('.business-top').children().css('color','#00A2C8');
$('.personal-top').children().css('color','#000000');
$('.business-top').click(function(e) {
e.preventDefault();
$(this).children().css('color','#00A2C8');
$('.personal-top a').css('color', '#000000');
$(this).css('margin-bottom', '0px');
$('.personal-tab').hide();
$('.business-tab').show();
$('.business-tab #block-nice_menus-2').hide();
});
$('.personal-top').click(function(e) {
e.preventDefault();
$(this).children().css('color','#00A2C8');
$('.business-top a').css('color', '#000000');
$(this).css('margin-bottom', '0px');
$('.personal-tab').show();
$('.business-tab').hide();
$('.personal-tab #block-nice_menus-2').show();
$('.personal-tab #block-nice_menus-1').hide();
});
});
我知道页面刷新时它会执行我编写的代码在准备好的文档中。当我单击“个人菜单”下的任何项目时,页面刷新后,它会再次转到“商务菜单”及其项目。我不希望这样,相反,我希望展示个人物品。我该怎么做?非常感谢您的帮助。
I have two tabs on top of my website named Business and Personal. When the page loads for the first time the items of the Business tab are shown in the bar below to the tabs.By clicking on the Perosnal it shows the personal items. This is working fine for me. Now I want to change something in the code, when I click on any Personal Menu Items the page refreshes, and it again shows the Business menu items.
Look at the website here
Here is my Jquery code :
$(document).ready(function() {
$('.business-tab').show();
$('.personal-tab').hide();
$('.business-tab #block-nice_menus-2').hide();
$('.business-top').children().css('color','#00A2C8');
$('.personal-top').children().css('color','#000000');
$('.business-top').click(function(e) {
e.preventDefault();
$(this).children().css('color','#00A2C8');
$('.personal-top a').css('color', '#000000');
$(this).css('margin-bottom', '0px');
$('.personal-tab').hide();
$('.business-tab').show();
$('.business-tab #block-nice_menus-2').hide();
});
$('.personal-top').click(function(e) {
e.preventDefault();
$(this).children().css('color','#00A2C8');
$('.business-top a').css('color', '#000000');
$(this).css('margin-bottom', '0px');
$('.personal-tab').show();
$('.business-tab').hide();
$('.personal-tab #block-nice_menus-2').show();
$('.personal-tab #block-nice_menus-1').hide();
});
});
I know when the page refreshes it execute the code which I written in document ready. When I click on any item under the Personal Menu, after the page refresh it goes again to the Business Menu and its items. I don't want that instead of it I want personal items to be shown. How can I do this ? Your help is really appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 cookie。
将一些代码附加到您的
click()
事件中,设置一个 cookie,告诉客户端他们是在企业端还是个人端浏览。我不会粘贴代码,因为我将直接从我发布的链接复制代码。但在您的click()
事件中,您需要添加Where 第二个参数告诉您它们正在导航到哪一侧。我只选择了 int,你可以选择 string、boolean,等等。
然后在代码顶部,您将
确保设置适当的过期时间!祝你好运。
You can use a cookie.
Append some code to your
click()
events that sets a cookie telling the client whether they are browsing in the business or personal side. I'm not going to paste code because I'll just copy code directly from the link I posted. But in yourclick()
events you'll want to addWhere the second argument tells you which side they are navigating on. I just chose int, you can choose string, boolean, whatever.
Then on the top of your code, you will have
Make sure you set appropriate expire times! Good luck.
我正在回答我的问题。我找到了解决方案,所以我只想分享它,以便其他人可以从答案中受益。
我已经存储了当前的网址并用它来解决我的问题。让我们看一下更新后的 jquery 代码。
});
I am answering my question. I found the solution so I just want to share it so anybody else can be benefitted from the answer.
I have store the current url and use it to solve my problem. Lets have a look at the updated jquery code.
});