javascript jquery mobile 中的 data-url 属性有什么作用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5917111/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does the data-url attribute do in jquery mobile?
提问by locoboy
Trying to figure out the basic structure of a page and came across a blog that had the data-url
attribute. What exactly does this mean?
试图找出页面的基本结构并遇到一个具有该data-url
属性的博客。这到底是什么意思?
采纳答案by ampersand
That attribute serves to identify pages that are auto-generated by jQM. From the jQM docs:
该属性用于标识由 jQM 自动生成的页面。从jQM 文档:
...Pages that are auto-generated by plugins use the following special data-url structure: <div data-url="page.html&subpageidentifier">
So, for example, a page generated by the listview plugin may have an data-url attribute like this: data-url="artists.html&ui-page=listview-1"
When a page is requested, jQuery Mobile knows to split the URL at "&ui-page" and make an HTTP request to the portion of the URL before that key. In the case of the listview example mentioned above, the URL would look like this: http://example.com/artists.html&ui-page=listview-1...and jQuery Mobile would request artists.html, which would then generate its sub-pages, creating the div with data-url="artists.html&ui-page=listview-1", which it will then display as the active page.
Note that the data-url attribute of the element contains the full URL path, not just the portion after &ui-page=. This allows jQuery Mobile to use a single consistent mechanism that matches URLs to page data-url attributes.
...由插件自动生成的页面使用以下特殊的 data-url 结构:<div data-url="page.html&subpageidentifier">
因此,例如,由 listview 插件生成的页面可能具有如下所示的 data-url 属性: data-url="artists.html&ui-page=listview-1"
请求页面时,jQuery Mobile 知道在“&ui-page”处拆分 URL,并向该键之前的 URL 部分发出 HTTP 请求。在上面提到的列表视图示例的情况下,URL 将如下所示:http: //example.com/artists.html&ui-page=listview-1...并且 jQuery Mobile 将请求 Artist.html,然后将生成它的子页面,使用 data-url="artists.html&ui-page=listview-1" 创建 div,然后它将显示为活动页面。
请注意,元素的 data-url 属性包含完整的 URL 路径,而不仅仅是 &ui-page= 之后的部分。这允许 jQuery Mobile 使用单一一致的机制将 URL 与页面 data-url 属性进行匹配。
回答by barry
The data-url attribute also serves to update the hash when using redirects or linking to directories. Check out the Redirects and linking to directoriessection.
data-url 属性还用于在使用重定向或链接到目录时更新哈希。查看重定向和链接到目录部分。