我正在開發使用.load函數動態加載頁面的網站。例如:index.php包含鏈接,點擊後加載其他頁面。其他頁面包含html和一些jQuery代碼(插件初始化等)。問題是jQuery代碼在動態加載後不起作用。 index.php的代碼:執行動態加載的jQuery代碼
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Example</title>
<script type="text/javascript">
$(document).ready(function(){
$(".load-page").click(function(){
$('.loaded-page-container').load('some_page_url', function(data, status, xhr) {
alert('page is loaded');
});
});
});
</script>
</head>
<body>
<a href="#" class="load-page">Load page</a>
<div class="loaded-page-container"></div>
</body>
</html>
而加載頁面的代碼:
<script type="text/javascript" src="autoNumeric-1.7.4.js"></script>
<script type="text/javascript" src="selectmenu/ui/jquery.ui.core.js"></script>
<script type="text/javascript" src="selectmenu/ui/jquery.ui.widget.js"></script>
<script type="text/javascript" src="selectmenu/ui/jquery.ui.position.js"></script>
<script type="text/javascript" src="selectmenu/ui/jquery.ui.selectmenu.js"></script>
<script type="text/javascript">
$('#number').autoNumeric({mDec:0,vMax:'9999999'}); //these statements doesn't work
$('#select').selectmenu({
width: 289
});
</script>
<div class="some-content">
HTML code that appears after current page loading.
<input type="text" value="" name="number" id="number" />
<select id="select">
<option value="some-val">Some value</option>
</select>
</div>
所以頁面加載,但jQuery插件遺憾的是沒有工作。有任何想法嗎?
您的幫助,將不勝感激。