从jquery mobile中的URL获取参数值 [英] Get param value from a URL in jquery mobile

查看:68
本文介绍了从jquery mobile中的URL获取参数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为servicesDetails.html的页面,该页面具有链接.URL如下所示

I have got a page called servicesDetails.html that has links.The url looks like below

../Myapp/servicesDetails.html?servicetype=Advanced&serviceid=1208

单击链接会加载一个名为 audioListPage 的内部页面,其中包含一些参数,链接看起来像这样

The links when clicked loads an internal page called audioListPage with some params,the link looks like this

<a href="#audioListPage?audioid=123&audiotype=mp3" class="loadAudio" data-role="button" data-mini="true" data-inline="true">

一旦加载audioListPage,URL就会更改为

Once the audioListPage is loaded the url changes to

../Myapp/servicesDetails.html?servicetype=Advanced&serviceid=1208#audioListPage?audioid=123&audiotype=mp3

在加载audioListPage时,我需要向用户显示audioid和audiotype,我该怎么做?

I need to display the user with the audioid and audiotype when the audioListPage loads,how do i do this?

基于下面的评论,我尝试了

Based on a comment below I tried this

$.urlParam = function(name){
var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
return results[1] || 0;
}

$('#audioListPage').live('pagecreate',function(event) {
   console.log($.urlParam('audioid '));//this is giving me an error
});

我检查了为什么会发生错误,并发现window.location.href仅给了我 ../Myapp/servicesDetails.html?servicetype=Advanced&ser​​viceid=1208,而不是更新的URL.不确定在正确的事件中我是否调用$ .urlParam()

I checked why the error was occuring and found that window.location.href is giving me only ../Myapp/servicesDetails.html?servicetype=Advanced&serviceid=1208, not the updated URL.Im not sure if Im calling the $.urlParam() at the right event

推荐答案

jQM文档建议使用以下插件之一作为参数:

jQM Documentation suggests using one of these plugins for parameters:

jQuery Mobile不支持将查询参数传递给 内部/嵌入式页面,但是您可以添加两个插件 您的项目支持此功能.有一个轻量级的页面 params插件和功能更全的 jQuery Mobile路由器插件 可以与ribs.js或spine.js一起使用.

jQuery Mobile does not support query parameter passing to internal/embedded pages but there are two plugins that you can add to your project to support this feature. There is a lightweight page params plugin and a more fully featured jQuery Mobile router plugin for use with backbone.js or spine.js.

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆