我的日期选择器有问题,由于某种原因,第一次加载日期选择器工作正常,让我选择日期,但是当我点击刷新(通过 ajax)时,日期选择器区域被刷新,但我无法使用日期选择器. 反正他们在附近吗?
我尝试使用不同的 id 并删除旧元素但没有多大成功:/
我在 php 中有一个显示日期的函数,在文件“datefunction.php”中
function getDateInfo()
{
$date = $_GET['date'];
$html = '<script>
$(document).load(function() {
$("#dt").datepicker(\'destroy\');
$("#dt").remove();
var mydate = $("#dt1").datepicker({ dateFormat: "dd-mm-yy" });
$("#dt1").click(function(){
mydate.datepicker("show");
});
});
});</script>
<label>Date1:</label>
<input type="text" name="dt" id="dt1" maxlength="10" size="12" value="' . $date . '" readonly="true" />';
return $html;
}
echo getDateInfo();
我有一个名为“dates.php”的页面
<script src="/script/jquery.js" type="text/javascript"></script>
<script type='text/javascript' src='/script/jquery-ui-1.8.9.custom.min.js'></script>
<script type='text/javascript' src='/script/jquery.datePicker.js'></script>
<script>
var bustcachevar=1; //bust potential caching of external pages after initial request? (1=yes, 0=no)
var bustcacheparameter="";
function ajaxpage(url, containerid, requesttype){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
}
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
} else return false
page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}
if (requesttype=='get'){
if (bustcachevar) bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
page_request.open('GET', url+bustcacheparameter, true)
page_request.send(null)
} else if (requesttype=='post') {
var poststr = "mytextarea1=" + encodeURI( document.getElementById("mytextarea1").value ) + "&mytextarea2=" + encodeURI( document.getElementById("mytextarea2").value );
page_request.open('POST', url, true);
page_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
page_request.setRequestHeader("Content-length", parameters.length);
page_request.setRequestHeader("Connection", "close");
page_request.send(parameters);
};
}
function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
document.getElementById(containerid).innerHTML=page_request.responseText
}
$(document).ready(function() {
var mydate = $("#dt").datepicker({ dateFormat: "dd-mm-yy" });
$("#dt").click(function(){
mydate.datepicker("show");
});
});
</script>
<?php
$date = "05-06-2009";
echo "<div id='datearea'><label>Date:</label>
<input type='text' name='dt' id='dt' maxlength='10' size='12' value='" . $date . "' readonly='true' /></div>";
echo "<a href='#' onclick='javascript:ajaxpage(\"datefunction.php?date=02-04-1999\", \"datearea\", \"get\");'>update</a>";
?>