如何在 Jquery Mobile 中的两个页面之间传递和获取参数? [英] How to pass and get Parameters between two Pages in Jquery Mobile?

查看:27
本文介绍了如何在 Jquery Mobile 中的两个页面之间传递和获取参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个演示应用程序来学习 Jquery Mobile 中的内容.我尝试了很多选择,但无法在一些事情上找到解决方案:-

  1. http://jsfiddle.net/sahil20grover1988/zZMXQ/48/ 在这种情况下当我在 Index page 中添加 paramUrl 时,它不是指向 Search Page
  2. 如果我不向索引页添加参数,那么我如何将参数索引页传递到搜索页.
  3. 我还需要帮助如何在搜索页面中检索参数 ??

解决方案

这有帮助吗?

JS

$('#page2').live('pageshow', function(event, ui) {alert('第 2 页 - CID:' + getParameterByName('cid'));});函数 getParameterByName(name) {var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);返回匹配 &&decodeURIComponent(match[1].replace(/+/g, ' '));}

HTML

<div data-role="内容"><ul data-role="listview" data-inset="true" data-theme="c" data-dividertheme="f"><li data-role="list-divider">主页<li><a href="?cid=1234#page2" rel="external">第 2 页</a>

<!-- 第 2 页 --><div data-role="page" id="page2"><div data-role="内容"><ul data-role="listview" data-inset="true" data-theme="c" data-dividertheme="f"><li data-role="list-divider">第2页<li><a href="?cid=4321#home">主页</a>

I am working on a some demo App to learn things in Jquery Mobile. I have tried a lot of options but not able to get solution on a few things :-

  1. http://jsfiddle.net/sahil20grover1988/zZMXQ/48/ In this case when i add param with Url in Index page it is not directing to Search Page
  2. In case if I dont add Params to Index page then how do I pass params from Index page to Search page.
  3. Also I need help how to retrieve the Params in search page ??

解决方案

Does this help?

JS

$('#page2').live('pageshow', function(event, ui) {
    alert('Page 2 - CID: ' + getParameterByName('cid'));
});

function getParameterByName(name) {
    var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
    return match && decodeURIComponent(match[1].replace(/+/g, ' '));
}

HTML

<div data-role="page" id="home">
    <div data-role="content">
        <ul data-role="listview" data-inset="true" data-theme="c" data-dividertheme="f">
            <li data-role="list-divider">
                Home Page
            </li>
            <li>
                <a href="?cid=1234#page2" rel="external">Page 2</a>
            </li>
        </ul>                
    </div>
</div>
<!-- page 2 -->
<div data-role="page" id="page2">
    <div data-role="content">
        <ul data-role="listview" data-inset="true" data-theme="c" data-dividertheme="f">
            <li data-role="list-divider">
                Page 2
            </li>
            <li>
                <a href="?cid=4321#home">Home Page</a>
            </li>
        </ul>
    </div>
</div>

这篇关于如何在 Jquery Mobile 中的两个页面之间传递和获取参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
前端开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆