2012-12-14 62 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

相關問題