data-add-back-btn =“true”不起作用
问题描述:
问题出在标题上。这是jsfiddle。这是代码:data-add-back-btn =“true”不起作用
<!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>
答
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>
下面是从jQuery的移动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);
}
谢谢!我错过了“超越第一视图”......因此,如果我需要第一页上的后退按钮(页面来自前面的外部页面),我将不得不“手动”添加它? – MarcoS
@MarcoS叶普,不幸的是“手工”,据我所知... –
此外,由于jQuery移动1.4此属性应添加到[标题,而不是页面div](http://stackoverflow.com/questions/20064843) /数据回加-BTN此结果未显示-A-后退按钮) –