jquery移动页面中未加载javascript
我最近构建了我的第一个jquery移动站点,它跨越了链接的单独html文件。按照jquery mobile文档中的说明,我在第一页的head标记之间加载了所有脚本:jquery移动页面中未加载javascript,jquery,ajax,jquery-mobile,Jquery,Ajax,Jquery Mobile,我最近构建了我的第一个jquery移动站点,它跨越了链接的单独html文件。按照jquery mobile文档中的说明,我在第一页的head标记之间加载了所有脚本: <script type="text/javascript" src="http://maps.google.com/maps/api/js?v=3.exp&sensor=true&libraries=places"></script><!--needed only on map.htm
<script type="text/javascript" src="http://maps.google.com/maps/api/js?v=3.exp&sensor=true&libraries=places"></script><!--needed only on map.htm-->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="js/ladot.js"></script><!--all custom script for pages in same js file-->
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.10.0/jquery.validate.min.js"></script><!--needed only on the two pages with forms that are to be validated-->
通过AJAX加载页面时,Jquery mobile将只加载目标页面的主体。这意味着将忽略标题中的任何内容,包括指向脚本或样式的任何链接。因此,您需要
我猜问题在于jquery mobile在ajax加载期间/之后没有访问窗口对象的权限。问题在于:google.maps.event.addDomListener(窗口“加载”,初始化)强> 你不需要这个。所有这一切只是加载初始化函数 我正在做一个简单的自动完成,删除addDomListener并从initialize函数中提取代码。请参阅下面删除的代码。这很好用 函数初始化(){//已删除
var input = /** @type {HTMLInputElement} */(document.getElementById('text-basic'));
var autocomplete = new google.maps.places.Autocomplete(input);
google.maps.event.addListener(autocomplete, 'place_changed', function() {
var place = autocomplete.getPlace();
if (!place.geometry) {
// Inform the user that the place was not found and return.
input.className = 'notfound';
return;
}
});
}//已删除
var input = /** @type {HTMLInputElement} */(document.getElementById('text-basic'));
var autocomplete = new google.maps.places.Autocomplete(input);
google.maps.event.addListener(autocomplete, 'place_changed', function() {
var place = autocomplete.getPlace();
if (!place.geometry) {
// Inform the user that the place was not found and return.
input.className = 'notfound';
return;
}
});
google.maps.event.addDomListener(此.window“加载”,初始化)//已删除我的主要问题似乎是通过HTTP访问页面时头部的脚本未加载。如果我刷新页面或在地址栏中键入URL并转到它,我的ladot.js和验证脚本似乎无法工作$委托(“#自行车架请求”,“页面创建”,函数(){$(“#车架表单”)。验证({你链接到其他页面标题中的所有脚本了吗?Romain,是的,我在每个页面的标题中都有链接。但我只包含运行该页面所需的链接。我应该加载网站上任何地方使用的每个脚本吗?这是我JS文件中的一个函数。我检查了错误控制台,看到他已经加载了js,但是这个函数在网站上不起作用。我猜这与我使用的语法有关。这里是开始部分function://Function 控制BSS表单$(文档)的表单验证错误。在(“pageshow”、“BSS请求”上,函数(){$(“#bssForm”)。验证({1.我目前已按照您在1中的建议设置了网站。所有脚本都位于每个页面的标题中,因此无论您从何处进入网站,所有需要的脚本都应加载并可用于后续页面。您可以在此处看到问题。右上角的按钮应将我链接回地图,但地图不会加载。您需要在链接到该页面后刷新地图,或者如果进入地图页面,则直接转到。所有后续页面都可以正常工作。但是,首先转到任何其他页面,地图将不会加载。顺便说一句,感谢您在这方面的帮助。我整天都在查看问题和谷歌教程,现在是晚上。问题是由于初始化未发生oogle.maps.event.addDomListener(窗口'load',initialize');在map.js中不会被触发,因为您使用的是ajax导航。您可以在本文中查看解决方案(基本上绑定到pageinit)。我尝试了,但没有成功。我的initialize函数和google.maps.event.addDomListener(窗口'load',initialize);其中实际包装为$('.map page')。在(“pageshow”,function(),因此每次我转到页面时都应该加载。我还尝试将pageshow更改为pageinit。我想现在我只是要禁用AJAX。感谢您的帮助。您确定触发了事件吗?
var input = /** @type {HTMLInputElement} */(document.getElementById('text-basic'));
var autocomplete = new google.maps.places.Autocomplete(input);
google.maps.event.addListener(autocomplete, 'place_changed', function() {
var place = autocomplete.getPlace();
if (!place.geometry) {
// Inform the user that the place was not found and return.
input.className = 'notfound';
return;
}
});