我目前正在使用表单导航并将表单参数从一个页面传递到另一个页面并通过查询字符串。
FirstPage
表单代码
<form name="input" action="new_page.html" method="get">
Username: <input type="text" name="user" />
<input type="submit" value="Submit" />
</form>
在新页面中,我尝试使用document.URL
获取查询字符串值。当旧页面指向新页面时,仅执行新页面的正文内容。脚本文件不在新页面中执行。因此,我无法在新页面中获取查询字符串值。
将参数从一个页面传递到另一个页面的过程适用于常规HTML页面,但在jQuery Mobile的情况下不起作用。
任何人都可以建议我将参数从一个jQuery Mobile页面传递到另一个页面的更好方法。任何帮助表示赞赏。
答案 0 :(得分:1)
关于更改页面时未执行的脚本:jQueryMobile page events not firing when navigating to a different html page
jQuery Mobile使用AJAX将新页面拉入DOM,这是您必须习惯创建jQuery Mobile网站的东西。这意味着应该在document.ready
或window.load
上运行的代码应绑定到其他事件,例如:pagecreate
,pageshow
,pageinit
。这是关于事件的jQuery Mobile的文档(可能非常有启发性):http://jquerymobile.com/demos/1.0/docs/api/events.html(请注意,页面事件开始大约一半)。
答案 1 :(得分:0)
关于在JQM中传递查询字符串参数,请查看带有代码示例的my previous answer。
希望这有帮助!
答案 2 :(得分:0)
如果从jquery移动页面重定向,则使用ajax加载新页面,因此新页面的JS将无法使用$(document).ready();
$(document).ready(function(){
//your awesome JS here won't work!
});
所以请改用:
$(document).bind('pageinit',function(event){
//the same JS here will work!
});
现在你的JS应该工作(至少对我有用!)。 有关详细信息,请转到here. 希望这有帮助!