当我通过 jquery ui datepicker 获得 to 和 from 日期的结果时,我试图关闭一个 ajax 命令。我得到“从”日期就好了,“到”日期总是不确定的,不管我做什么。有任何想法吗?
function getInfo()
{
var beg = $("#from").val();
var end = $("to").val();
alert($("to").val()); <-----this is always undefined
$("#cdrData").hide();
$.ajax({
type: "GET",
url: "cdrs/getCDRS.php",
data: "begDate=" + beg + "&endDate=" + end,
success: function(result){
$("#cdrData").html(result);
$("#cdrData").slideDown('slow');
}
});
}
和php形式:
<form method='POST' id='getCDRS' name='getCDRS'>
<label for="from">From</label>
<input type="text" id="from" name="from" />
<label for="to">to</label>
<input type="text" id="to" name="to" />
<input type='button' value='submit' onclick="getInfo()";>
</form>
和标准的日期选择器脚本:
<script>
$(function() {
$( "#from" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 3,
onClose: function( selectedDate ) {
$( "#to" ).datepicker( "option", "minDate", selectedDate );
}
});
$( "#to" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 3,
onClose: function( selectedDate ) {
$( "#from" ).datepicker( "option", "maxDate", selectedDate );
}
});
});
</script>