Jquery Mobile - $ .mobile.changepage没有加载外部.JS文件 [英] Jquery Mobile - $.mobile.changepage not loading external .JS files
问题描述
因此,我很难让 $。mobile.changePage
正常运作。我称之为:
$ $ $ $ mobile.changePage(DataformsM-AddRecord.html,{transition:slide });
但由于某些原因,当加载HTML页面时,没有任何外部.js文件包括我写的实际上做了些什么)。我正在遵循
$ b
-Jquery
- (CUSTOM JS)
-Jquery Mobile的重要加载约定
有谁知道为什么没有正确加载?此外,页面展示功能也没有被解雇,这很奇怪。它看起来像这样:
$(div [data-role * ='page'])。live('pageshow ',function(event,ui){
loadFormFields();
});
现在页面被渲染,但没有任何功能发生。如果我破解并执行如下操作:
document.location.href =DataformsM-AddRecord.html;
它会正常运作。
jQuery Mobile不会将整个页面拖入dom中,它首先抓取 data-role =page
元素及其后代,并将其引入当前的dom。
因此,< head>
我通常会将所有功能性JavaScript放到索引页上,然后当外部页面加载到dom时,它们可以您可以将JavaScript代码放置在 data-role =page中
元素,当jQuery Mobile执行页面的AJAX加载时,它将被包含。
更新
一个好的系统是将所有JS放入包含文件并将其包含在网站的每个页面上。如果页面通过AJAX进入DOM,它将被忽略,但如果某人在您网站的某处刷新,那么JS将可用。
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"} );
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
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";
It will function properly.
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.
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.
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.
UPDATE
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屋!