【发布时间】:2011-12-02 14:19:23
【问题描述】:
我有 2 页。 1 是 jQuery 的 datepicker 演示,另一个是用于加载 datepicker 演示页面的 AJAX 页面。当我直接访问 datepicker 页面时,日期选择器工作正常,如示例中所示。但是当我尝试使用 ajax 调用加载它时,选择器似乎根本不起作用。
这里是main.php页面代码
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else {
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","development-bundle/demos/datepicker/default.html",true);
xmlhttp.send();
}
</script>
</head>
<body>
<div id="myDiv"><h2>Let AJAX change this text</h2></div>
<button type="button" onclick="loadXMLDoc()">Change Content</button>
</body>
</html>
这是 datepicker 页面代码(它与 jquery 中的演示代码相同)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Datepicker - Default functionality</title>
<link rel="stylesheet" href="../../themes/base/jquery.ui.all.css">
<script src="../../jquery-1.6.2.js"></script>
<script src="../../ui/jquery.ui.core.js"></script>
<script src="../../ui/jquery.ui.widget.js"></script>
<script src="../../ui/jquery.ui.datepicker.js"></script>
<link rel="stylesheet" href="../demos.css">
<script>
$(function() {
$( "#datepicker" ).datepicker();
});
</script>
</head>
<body>
<div class="demo">
<p>Date: <input type="text" id="datepicker"></p>
</div><!-- End demo -->
<div class="demo-description">
<p>The datepicker is tied to a standard form input field. Focus on the input (click, or use the tab key) to open an interactive calendar in a small overlay. Choose a date, click elsewhere on the page (blur the input), or hit the Esc key to close. If a date is chosen, feedback is shown as the input's value.</p>
</div><!-- End demo-description -->
</body>
</html>
我真的迷路了。日期选择器页面不能与 AJAX 一起使用。希望有人可以在这里提供帮助。
【问题讨论】:
-
您可能会遇到一些严重的问题,因为将整个 HTML 文档填充到现有页面上的
<div>中是无效的。
标签: javascript jquery ajax