[英]jQuery getfile(); in bootstrap modal box
我需要使用jQuery getfile();
加載外部.js
文件getfile();
打開bootstrap3模式框時。
JS:
$(document).ready(function () {
var stillPresent = false;
$('#myModal').on('shown.bs.modal', function (e) {
$.getScript("http://localhost/user/js/data.js");
if(stillPresent == false){
$('#us2').locationpicker({
location: {
latitude: 35.722606,
longitude: 51.3843825
},
radius: 300,
inputBinding: {
latitudeInput: $('#us2-lat'),
longitudeInput: $('#us2-lon'),
radiusInput: $('#us2-radius'),
locationNameInput: $('#us2-address')
}
});
}
})
});
HTML:
<a data-toggle="modal" href="#myModal" class="btn btn-primary">Launch modal</a>
問題:此代碼在打開模式框后NOT
加載.js
文件。 單擊並打開模式框后,我需要加載data.js
如何修復我的代碼並加載它?
我相信這是一個同步問題,因為腳本加載后沒有使用回調,因此getScript的第二個參數是success
回調。
$.getScript( "http://localhost/user/js/data.js", function( data, textStatus, jqxhr ) {
console.log( data ); // Data returned
console.log( textStatus ); // Success
console.log( jqxhr.status ); // 200
console.log( "Load was performed." );
});
查看是否正在發生這種情況,並根據需要在回調中繼續執行代碼。
最好。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.