【问题标题】:Change page name based on the tab根据选项卡更改页面名称
【发布时间】:2017-05-05 18:05:15
【问题描述】:

我有一个使用 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();

}

任何帮助将不胜感激

【问题讨论】:

    标签: javascript jquery jquery-mobile


    【解决方案1】:

    您希望附加到每个选项卡项的单击处理程序。只需将此代码块添加到您的 $(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/

    【讨论】:

    • 谢谢 :) 完美运行
    【解决方案2】:

    我不知道会发生什么,但这是我的方法 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);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-13
      • 1970-01-01
      • 1970-01-01
      • 2011-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多