2013-04-26 50 views
0

當我嘗試打開一個對話框時,它從它打開的頁面重新加載JavaScript文件。 頁面不刷新,它只是JavaScript。jQuery Mobile對話框從它被打開的頁面重新加載JavaScript從

<!DOCTYPE html> 
<html> 
<head> 
<title>Test</title> 
<link rel="stylesheet" href="css/frameworks/jquery.mobile-1.3.0.css"> 
<script src="js/jquery-1.9.1.js"></script> 
<script src="js/jquery.mobile-1.3.0.js"></script> 
<script src="js/test.js"></script> 
</head> 
<body> 
    <div id="page" data-role="page"> 
     <a href="dialog.html" data-rel="dialog" transition="pop" data-role="button" data-icon="check" data-inline="true">Open Dialog</a> 
    </div> 
</body> 
</html> 

dialog.html只是默認頁面,test.js包含:

$(document).bind('pageinit', function() { 
    alert("fire"); 
} 

如何預防呢?

回答

0

這是從外部file.html打開一個對話框,以正確的方式。

$.mobile.changePage('file.html', { role: 'dialog', transition: 'pop' }); 

它只會在<body>內加載代碼。

按鈕標記

<a href="#" id="open-dialog" data-role="button" >Open Dialog</a> 

代碼

$('#open-dialog').on('click', function() { 
$.mobile.changePage('file.html', { role: 'dialog', transition: 'pop' }); 
}); 
+0

我實現你的代碼,但結果是一樣的:顯示test.js的警報打開對話框時。 難道它不得不用$ .mobile.ajaxEnabled做些什麼嗎? – joekeee 2013-04-26 11:31:03

+0

@joekeee它應該被啓用,因爲它通過Ajax加載對話框。 – Omar 2013-04-26 12:11:25

相關問題