简体   繁体   English

jQM-使用$ .mobile.changePage时Javascript在'file.html'中不起作用

[英]jQM - Javascript doesn't work in 'file.html' when use $.mobile.changePage

I'm trying to make transition between two .html files using jQM (just for test): 我正在尝试使用jQM在两个.html文件之间进行转换(仅用于测试):

index.html: index.html:

 <script>

  function Go(){
     var url = "go.html?go='123'";
     $.mobile.changePage(url, {transition: "slide"});
  }

 </script>

<body>
   <button onclick='Go();'>Go!</button>
</body>

go.html: go.html:

  <script>
$( document ).on("#mainpage", "pageinit", function() {
  // CODE GET URL VARs

   function getUrlVars() {
    var vars = {};
    var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi,             function(m,key,value) {
    vars[key] = value;
    });
    return vars;
  }

  var go = getUrlVars()['go'];

  alert(go);
});
  </script>

The transition works fine, and i see (in the url browser) the variable ' go ' is there (123). 过渡工作正常,我看到(在url浏览器中)变量“ go ”在那里(123)。

When the translation finish, the alert doesn't work and i have to refresh the page (F5) to see the alert (' 123 '): JAVASCRIPT IN go.html DOESN'T WORK. 翻译完成后,警报不起作用,我必须刷新页面(F5)才能看到警报(' 123 '): go.html中的 JAVASCRIPT 不起作用

How can i fix this issue? 我该如何解决这个问题?

The scripts you want executed on that page need to be handled on the pageinit or pagechange event in jQm. 您要在该页面上执行的脚本需要在pageinitpagechange事件中处理。 Go read the scripting section on the jQm docs. 阅读jQm文档上的脚本部分

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM