我在 ajax 调用中加载我的 datepicker 脚本,它可以正常工作并按应有的方式加载 datepicker。我遇到的问题是,当我点击一天时,它不会触发 onclick 功能。
如果我在单独的窗口中自行加载日期选择器页面,那么它可以正常工作
AJAX 调用
function dates(str2){
var event = findSelection("event");
if (str2 == "")
{
document.getElementById("dates").innerHTML = "";
return;
}
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("dates").innerHTML = xmlhttp.responseText;
$("#datepicker").datepicker();
}
}
xmlhttp.open("GET", "dates.php?event=" +
event + "&type=" + document.getElementById("type").value, true);
xmlhttp.send();
}
日期.php
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>jQuery UI Datepicker - Display inline</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script>
$(function () {
$('#datepicker').datepicker({
dateFormat: 'dd-mm-yy',
numberOfMonths: 1,
onSelect: function (selected, evnt) {
alert("I am an alert box!");
}
});
}); </script>
</head>
<body>
Date: <div id="datepicker"></div>
</body>
</html>