data-add-back-button =“true”不起作用

时间:2012-12-01 19:01:37

标签: jquery-mobile

问题在于标题。这是jsfiddle。这是代码:

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Back button test</title>
<link href="//code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" rel="stylesheet">
<script src="//code.jquery.com/jquery-1.8.1.min.js"></script>
<script src="//code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
</head>
<body>
    <div id="home" data-role="page" data-add-back-btn="true">
        <div data-role="header"><h1>header</h1></div>
        <div data-role="content">content</div>
    </div>
</body>
</html>

1 个答案:

答案 0 :(得分:7)

JQM仅在第一个视图之外的页面上添加一个后退按钮。如果您使用data-add-back-btn="true"添加其他页面,则会显示:

<body>
<!-- -->
<div id="home" data-role="page" data-add-back-btn="true">
    <div data-role="header"><h1>header</h1></div>
    <div data-role="content">
        content <a href="#page2">page2</a>
    </div>

</div>
<div id="page2" data-role="page" data-add-back-btn="true">
    <div data-role="header"><h1>Page 2</h1></div>
    <div data-role="content">Back-button visible</div>
</div>
</body>

http://jsfiddle.net/c2pUt/4/


以下是来自jquery-mobile-1.2.0.js的片段(从第4800行开始):

// Auto-add back btn on pages beyond first view
if (o.addBackBtn && role === "header" 
    && $(".ui-page").length > 1 
    && $page.jqmData("url") !== $.mobile.path.stripHash(location.hash) 
    && !leftbtn) {

    backBtn = $("<a href='javascript:void(0);' class='ui-btn-left' data-" + $.mobile.ns + "rel='back' data-" + $.mobile.ns + "icon='arrow-l'>" + o.backBtnText + "</a>")
    // If theme is provided, override default inheritance
    .attr("data-" + $.mobile.ns + "theme", o.backBtnTheme || thisTheme)
        .prependTo($this);
}