【问题标题】:jQuery mobile passing parameter from one page to anotherjQuery mobile 将参数从一个页面传递到另一个页面
【发布时间】:2011-12-01 22:45:01
【问题描述】:

我目前正在使用表单来导航并将表单参数从一个页面传递到另一个页面,并通过查询字符串。

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 页面传递到另一个页面的更好方法吗?任何帮助表示赞赏。

【问题讨论】:

    标签: jquery jquery-mobile


    【解决方案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(请注意,页面事件大约从一半开始)。

    【讨论】:

      【解决方案2】:

      关于在 JQM 中传递查询字符串参数,请查看 my previous answer 的代码示例。

      希望这会有所帮助!

      【讨论】:

        【解决方案3】:

        如果您从 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. 希望这会有所帮助!

        【讨论】:

          猜你喜欢
          • 2011-01-02
          • 2016-01-24
          • 1970-01-01
          • 1970-01-01
          • 2013-01-24
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多