2013-04-26 61 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