jQuery手机:在散列URL中提供参数? [英] jQuery mobile: supply parameters in hash URL?
问题描述
以下是一些示例代码。在主页的内容
部分,我希望能够链接到一个名为例如'#photo-123'并让它加载下面的'photo'页面。然后我会从网址中提取照片编号,并加载图片123.
<! - 主页 - >
< div data-role =pageid =home>
< div data-role =header>
< h1>主页< / h1>
< / div>
< div data-role =content>
< p>< a href =#photodata-role =button> Photo ###< / a>< / p>
< / div>
< / div>
<! - - 相片页 - >
< div data-role =pageid =photo>
< div data-role =header>
< h1>照片###< / h1>
< / div>
< div data-role =content>
< img id =myphotosrc =/>
< / div>
< / div>
这样我就可以重复使用该网址,即用户可以直接重新加载该网页。
是否可以使用jQuery mobile在散列URL中传递参数? (或者通常用HTML - 我知道它可以用于例如BBQ插件,但如果可能的话,我宁愿避免插件)
<您可以使用全局事件挂钩和数据标签来处理和存储内部参数(即在#blah - >#blah2之间)转换:
-
在你的HTML中,你可以去
< a href =#photodata-params =id = 123> ....< / b>
-
拦截所有链接上的点击并查找特定的数据元素,例如data-params:
$('a')。live('click',
function(e){
params = $(e.target) .jqmData(params)
}
)
在这种情况下,您正在创建一个全局 params 对象,您应该可以从所有代码以统一的方式访问该对象。
I'm working in jQuery mobile, which is great. I have a question about supplying parameters inside the hash part of a URL.
Here's some example code. In the content
part of the home page, I'd like to be able to link to a page called e.g. '#photo-123' and have it load the 'photo' page below. I'd then extract the photo number from the URL, and load image 123.
<!-- Home page -->
<div data-role="page" id="home">
<div data-role="header">
<h1>Home</h1>
</div>
<div data-role="content">
<p><a href="#photo" data-role="button">Photo ###</a></p>
</div>
</div>
<!-- Photo page -->
<div data-role="page" id="photo">
<div data-role="header">
<h1>Photo ###</h1>
</div>
<div data-role="content">
<img id="myphoto" src="" />
</div>
</div>
This is so I can reuse the URL, i.e. the user can reload that page directly.
Is it possible to pass parameters inside a hash URL with jQuery mobile? (or indeed with HTML generally - I know it's possible with e.g. the BBQ plugin, but I'd rather avoid plugins if possible)
You can use global event hooks and data- tags to process and store parameters for internal (i.e. between #blah -> #blah2) transitions:
In your HTML you can go
< a href="#photo" data-params="id=123">....< /a>
Intercept the clicks on all links and look for a specific data- element, say, data-params:
$('a').live('click', function(e) { params = $(e.target).jqmData("params") } )
In this case you are creating a global params object, which you should be able to access in a uniform manner from all your code.
这篇关于jQuery手机:在散列URL中提供参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!