Jquery Mobile - $.mobile.changepage 不加载外部 .JS 文件 [英] Jquery Mobile - $.mobile.changepage not loading external .JS files

查看:21
本文介绍了Jquery Mobile - $.mobile.changepage 不加载外部 .JS 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我很难让 $.mobile.changePage 正常运行.我这样称呼它:

So I am having a hard time getting $.mobile.changePage to function properly. I call it like this:

$.mobile.changePage( "DataformsM-AddRecord.html", { transition: "slide"} );

但由于某种原因,当加载 HTML 页面时,没有包含任何外部 .js(我编写的实际执行某些操作的文件).我正在遵循

But for some reason, when the HTML page is loaded, none of the external .js (the files that I wrote to actually do something) are included. I am following the significant loading conventions of

-Jquery
-(CUSTOM JS)
-Jquery Mobile

有谁知道为什么这不能正确加载?此外,pageshow 功能也没有被触发,这很奇怪.它看起来像这样:

Does anyone know why this is not getting loaded properly? Also, the pageshow function is not getting fired either, which is strange. It looks like this:

$("div[data-role*='page']").live('pageshow', function(event, ui) { 

    loadFormFields();

});

现在页面已呈现,但没有任何功能性的事情发生.如果我破解它并执行以下操作:

Now the page is rendered, but none of the functional things happen. If I hack it and do something like this:

document.location.href="DataformsM-AddRecord.html";

它将正常运行.

推荐答案

jQuery Mobile 不会将整个页面拉入 dom,它会抓取 first data-role="page" 元素及其后代并将其拉入当前 dom.

jQuery Mobile does not pull the whole page into the dom, it grabs the first data-role="page" element and its descendants and pulls that into the current dom.

因此文档的 中的任何脚本都不会包含在内.

So any scripts in the <head> of the document will not be included.

我通常将我网站的所有功能 JavaScript 放在索引页面上,然后当外部页面加载到 dom 时,它们可以从已经加载的脚本中受益.

I generally put all the functional JavaScript for my site on the index page and then when external pages are loaded into the dom they can benefit from the already loaded scripts.

此外,您可以将 JavaScript 代码放在 data-role="page" 元素中,它会在 jQuery Mobile 对页面进行 AJAX 加载时包含在内.

Also, you can place JavaScript code inside the data-role="page" element and it will be included when jQuery Mobile does its AJAX load of the page.

更新

一个很好的系统是将您的所有 JS 放入一个包含文件中,并将其包含在站点的每个页面上.如果通过 AJAX 将页面带入 DOM,它将被忽略,但如果有人刷新您站点中的某个位置,则 JS 将可用.

A good system for this is to put all of your JS into an include file and include it on each page of the site. It will be ignored if pages are brought into the DOM by AJAX, but if someone refreshes somewhere in your site, the JS will be available.

这篇关于Jquery Mobile - $.mobile.changepage 不加载外部 .JS 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆