的 问题描述: 强>
正如Omar在评论中指出的那样,对于单页模型,在以下条件下,第一个JQM页面在DOM中重复:
data-url=""
从另一个JQM页面导航到第一页时发生重复。
的 例 强> : 请参阅index.html和index2.html下的两个文件。
index.html包含一个指向index2.html的selectmenu和一个导航按钮。
index2.html只包含一个导航回index.html的按钮(请注意,这是一个带有href到index.html的锚标记,属性 data-rel="back" 未使用。)
data-rel="back"
的 index.html的: 强>
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css"> <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script> <script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> </head> <body> <div data-role="page"> <div data-role="main" class="ui-content"> <p>Page 1 content</p> <select name="type[]" id="type" multiple="multiple" data-native-menu="false" data-inline="true" > <!-- options --> <option>Select...</option> <option value="1">Audi</option> <option value="2">BMW</option> <option value="3">Ford</option> </select> <a href="index2.html" data-role="button" data-inline="true" data-icon="star">Page 2</a> </div> </div> </body> </html>
的 index2.html: 强>
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css"> <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script> <script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> </head> <body> <div data-role="page"> <div data-role="main" class="ui-content"> <p>Page 2 content</p> <a href="index.html" data-role="button" data-inline="true" data-icon="home">Home</a> </div> </div> </body> </html>
这些文件也可以在这里找到: https://www.elitesystemer.no/demo/JQMduplication/
要重现此问题,请执行以下操作:
现在检查DOM(大多数浏览器中的F12键)。将有一个页面具有该属性(在上面的URL的情况下) data-url="/demo/JQMduplication/" 以及具有数据属性的第二页 data-url="/demo/JQMduplication/index.html" 和 data-external-page="true" 。
data-url="/demo/JQMduplication/"
data-url="/demo/JQMduplication/index.html"
data-external-page="true"
的 固定 强>
要更正此行为并避免页面重复,请使用data属性 data-url 提供正确的URL,而不是用于请求页面的URL,例如: data-url="/path/index.html"
data-url
data-url="/path/index.html"
的 例: 强> 正如上例中的正确index.html将是:
<div data-role="page" data-url="/demo/test/index.html"> <div data-role="main" class="ui-content"> <p>Page 1 content</p> <select name="type[]" id="type" multiple="multiple" data-native-menu="false" data-inline="true" > <!-- options --> <option>Select...</option> <option value="1">Audi</option> <option value="2">BMW</option> <option value="3">Ford</option> </select> <a href="index2.html" data-role="button" data-inline="true" data-icon="star">Page 2</a> </div> </div>