2012-12-14 66 views

回答

2
var jsonp = document.createElement("script"); 
      jsonp.type = "text/javascript"; 
      jsonp.src = "cubiq-iscroll-bad88fb/src/iscroll.js"; 
      document.getElementsByTagName("body")[0].appendChild(jsonp); 

这应该工作好的。如果.js的工作没有错误,希望这有助于。

1

你可以试试:

<script> 
$('#summaryPage').live('pageinit', function(){ 
    var oHead = document.getElementsByTagName('HEAD').item(0); 
    var oScript= document.createElement("script"); 
    oScript.type = "text/javascript"; 
    oScript.src="other.js"; 
    oHead.appendChild(oScript); 
}); 
</script> 
+0

我想这没有运气。我将“other.js”更改为我的“script.js”,并将其粘贴在两个单独的头部中并在它们之间导航。我也只是将它粘贴在script.js中,但是nada。感谢寿。 – Squirrl

+0

请参阅编辑答案,也许你正在听完整个错误的事件。请接受/ upvote,如果有帮助 – iOSAndroidWindowsMobileAppsDev

1

因为.live将被弃用,你也可以

$(document).on('pageinit', '#summaryPage', function(){ 
    //append head element and custom script 
}); 

它也可能是您加载脚本太晚,当然,如果我是你只要文档和/或设备准备就绪,我会立即执行此操作,然后当页面进入时检查元素是否存在,如果不存在,触发创建。您还可以在jQuery Mobile API中听到的事件,例如pagebeforecreate

或更好,但仍然将代码放在一个全局函数没有名字:

function(){ 
//append your script here 
} 

你可以在API中阅读了关于jquery.com文档

1

尝试页面显示之前运行它:

$('div:jqmData(role="page")').live('pagebeforeshow',function(){ 
    $.getScript('cubiq-iscroll-bad88fb/src/iscroll.js'); 
}); 

jQuery mobile $(document).ready equivalent

+0

.live()已被弃用,所以最好避免使用它。 – jacobross85

相关问题