[英]jQuery Tab Menu with Remember Last Position
I have jQuery
tab menu call ajax. 我有
jQuery
选项卡菜单调用ajax。
Menu is working perfect, now How can I set the tab automatically detect last tab click even page refreshed. 菜单运行正常,现在如何设置选项卡自动检测上次单击的选项卡,即使刷新页面也是如此。
You can see the fiddle here: https://jsfiddle.net/waspinator/rw8ujfg3/ 您可以在这里看到小提琴: https : //jsfiddle.net/waspinator/rw8ujfg3/
<ul class="nav nav-tabs tabs-up " id="friends">
<li active><a href="/gh/gist/response.html/3843293/" data-target="#contacts" class="media_node active span" id="contacts_tab" data-toggle="tabajax" rel="tooltip"> Contacts </a></li>
<li><a href="/gh/gist/response.html/3843301/" data-target="#friends_list" class="media_node span" id="friends_list_tab" data-toggle="tabajax" rel="tooltip"> Friends list</a></li>
<li><a href="/gh/gist/response.html/3843306/" data-target="#awaiting_request" class="media_node span" id="awaiting_request_tab" data-toggle="tabajax" rel="tooltip">Awaiting request</a></li>
<div class="tab-content">
<div class="tab-pane active" id="contacts">
</div>
<div class="tab-pane" id="friends_list">
</div>
<div class="tab-pane urlbox span8" id="awaiting_request">
</div>
</div>
JS JS
$('[data-toggle="tabajax"]').click(function(e) {
var $this = $(this),
loadurl = $this.attr('href'),
targ = $this.attr('data-target');
$.get(loadurl, function(data) {
$(targ).html(data);
});
$this.tab('show');
return false;
});
I just know it will be using cookie right? 我只知道它将使用Cookie对吗? But how can I set it?
但是我该如何设置呢?
Use document.cookie="your format" to store data in cookie, then check it accordingly 使用document.cookie =“ your format”将数据存储在cookie中,然后进行相应检查
I think it may got a better answer, but that's all i can do 我认为可能会有更好的答案,但这就是我所能做的
Hope i can help you, Here you go 希望我能为您服务,您来了
if (document.cookie.indexOf("opentab=") >= 0) {
var x = document.cookie;
if(x=='opentab=1st'){
var dataid = '#contacts_tab';
}
else if(x=='opentab=2nd'){
var dataid = '#friends_list_tab';
}
else{
var dataid = '#awaiting_request_tab';
}
var loadurl = $(dataid).attr('href');
var targ = $(dataid).attr('data-target');
$.get(loadurl, function(data) {
$(targ).html(data);
});
$(dataid).tab('show');
}
$('[data-toggle="tabajax"]').click(function(e) {
var $this = $(this),
loadurl = $this.attr('href'),
id = $this.attr('id'),
targ = $this.attr('data-target');
if(id == "contacts_tab"){
document.cookie = "opentab=1st";
}
else if(id == "friends_list_tab"){
document.cookie = "opentab=2nd";
}
else{
document.cookie = "opentab=3rd";
}
$.get(loadurl, function(data) {
$(targ).html(data);
});
$this.tab('show');
return false;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.