根据标签更改页面名称
问题描述:
我有一个使用jquery mobile和nativedroid2构建的小应用程序。根据标签更改页面名称
我想知道是否有可能根据标签名称更改页面标题名称?
举例http://jsfiddle.net/livewirerules/2a7so7r5/1/您将看到页面标题为Friends
,而我的活动标签为Friends
,所以当我移动到下一个标签时。 Work
页面标题应该相应改变
下面是我的演示JS代码
$(document).on("pagecreate", "#page1", function() {
$("div[role=main]").on("swipeleft", function (event) {
changeNavTab(true);
});
$("div[role=main]").on("swiperight", function (event) {
changeNavTab(false);
});
});
function changeNavTab(left) {
var $tabs = $('ul[data-role="nd2tabs"] li');
console.log($tabs);
var len = $tabs.length;
var curidx = 0;
$tabs.each(function(idx){
if ($(this).hasClass("nd2Tabs-active")){
curidx = idx;
}
});
var nextidx = 0;
if (left) {
nextidx = (curidx >= len - 1) ? 0 : curidx + 1;
} else {
nextidx = (curidx <= 0) ? len - 1 : curidx - 1;
}
$tabs.eq(nextidx).click();
}
任何帮助将不胜感激
答
要附加到每个选项卡项目的点击处理程序。只需将此代码块添加到您的$(document)
函数中即可。并为您的页面标题元素设置一个ID。
<h1 id="heading" class="wow fadeIn" data-wow-delay='0.4s'>Friends</h1>
$('ul[data-role="nd2tabs"] li').on('click',function(){
$("#heading").html($(this).html());
});
下面是更新小提琴 http://jsfiddle.net/2a7so7r5/18/
答
我不知道什么期望,但是这是我的aproach Modified example
function changeNavTab(left) {
var $active = $('ul[data-role="nd2tabs"] li.nd2Tabs-active');
if(left){
var $moveto = $active.next().length ? $active.next() : $('ul[data-role="nd2tabs"] li:first');
}else{
var $moveto = $active.prev().length ? $active.prev() : $('ul[data-role="nd2tabs"] li:last');
}
var title = $moveto.text();
$("h1.ui-title").text(title);
}
+0
您的解决方案是维护导航, upvoted! – deblocker
谢谢:)完美的作品 – LiveEn