javascript - 如何以编程方式更改 jquerymobile 页面并将数据发送到该页面?

标签 javascript jquery jquery-mobile

伙计们!
我使用 jquerymobile 1.3.0 和 jquery 1.9.1
我有 2 个(更多)jquerymobile 页面。
例如:

<div data-role="page" id="firstPage">
    <!-- Header -->
    <div data-role="header">
        <h3>First page</h3>
    </div>
    <!-- Body -->
    <div data-role="content">
        some content ...
    </div>
</div>

<div data-role="page" id="secondPage">
    <!-- Header -->
    <div data-role="header">
        <h3>Second page</h3>
    </div>
    <!-- Body -->
    <div data-role="content">
        some content ...
    </div>
</div> 

我需要从第一页转到第二页,并发送一些参数,通常是 URL
我尝试使用这种方法:

$.mobile.changePage('#secondPage',
    {
        data: {id: 123, module: 111}
    }
);

此方法后,第一页的元素被隐藏,url 更改为
www.mydomain.com/main.html?id=123&module=111 但页面没有改变。我想为了将页面更改为该页面的哈希 URL。
并且 URL 的格式必须是

www.mydomain.com/main.html?id=123&module=111#secondPage

然后我尝试使用:

location.href += '?id=1234&module=111#secondPage';

这个方法行得通 ))) 但是当我尝试返回 firstPage 时,页面已更改,但 URL 中仍保留数据

www.mydomain.com/main.html?id=123&module=111

然后我尝试使用下一个方法删除这些数据

location.href = location.href.replace(location.origin, "").replace(location.pathname, "");

但是在这个方法之后我的 firstPage 被循环改变。
请大家帮忙。如何将数据发送到secondPage 并在我返回firstPage 时删除此数据?
我的后退按钮使用 native jquerymobile 方法返回。

<a data-theme="a" data-role="button" data-transition="fade" href="#firstPage" data-iconpos="notext" class="ui-btn-left backButton"></a>

附言。对不起我的英语,我的英语水平是初级

最佳答案

如果您在一个 html 中定义了两个页面,则不必使用 URL 将参数发送到其他页面。只需使用 javascript 变量和页面事件即可使用它们。

如果您使用 URL 参数来运行服务器端代码,只需使用不同的 .html 文件即可。一个 html 文件,一种页面样式。

但为了在移动设备上实现平滑的过渡效果和最佳用户实验,我更喜欢使用 AJAX 并实时创建/更改页面,

最好的问候

关于javascript - 如何以编程方式更改 jquerymobile 页面并将数据发送到该页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15425306/

相关文章:

javascript - 自行车构造器不断添加齿轮而不是输出指定数量

javascript - 在使用 while 循环遍历元素时遇到问题

jQuery Mobile - 切换 $.mobile.showPageLoading()

jquery移动子页面不起作用

javascript - 我怎样才能通过thymeleaf th :replace?传递这个字符串

javascript - 如何使用 mocha.js 测试多个异步流程事件

jquery - 禁用日历中的所有日期

Javascript访问div

css - 更改 jQuery Mobile 1.4.0 中单选按钮的样式

PHP在Wordpress中自动编码&