我有一个从-> 到日期选择器的使用选择器,它通过 som .ajax 代码,然后加载一个谷歌折线图。
我的问题是,在 Chrome 中,当单击按钮并且脚本运行一次时,输入字段“from”和“to”在单击时不会显示日期选择器。
如前所述,这仅在 Chrome 中,在 IE 和 Firefox 中,输入字段将始终显示 Datepicker-popups。
这是我的 Datepicker 的 index.php Javascript 代码:
<script type="text/javascript" id="js">
$(document).ready(function() {
var dates = $("#from, #to").live('focus', function() {
$(this).datepicker({
defaultDate: "+1w",
numberOfMonths: 1,
dateFormat: 'yy-mm-dd',
beforeShow: function( ) {
var other = this.id == "from" ? "#to" : "#from";
var option = this.id == "from" ? "maxDate" : "minDate";
var selectedDate = $(other).datepicker('getDate');
$(this).datepicker( "option", option, selectedDate );
}
})
.change(function(){
var other = this.id == "from" ? "#to" : "#from";
if ( $('#from').datepicker('getDate') > $('#to').datepicker('getDate') )
$(other).datepicker('setDate', $(this).datepicker('getDate') );
});
});
});
google.load('visualization', '1', {'packages':['corechart']});
$(document).ready(function() {
$("#btn").click(function() {
var from = $("#from").val();
var to = $("#to").val();
$('#box1Res , #box2Res, #box3Res').html('<img src="ajax-loader.gif" />'); // placeholder
$.ajax( {
url : 'getjson.php',
type : 'post',
dataType: 'text',
data: {tid1: from, tid2: to},
success : function( data ) {
$('#box1Res').html($('#inner_1' , data).html());
$('#box2Res').html($('#inner_2' , data).html());
$('#box3Res').html($('#inner_3' , data).html());
var test = ($('#graph_4' , data).html());
$('#chart_div').html('<img src="ajax-loader.gif" />');
$("#chart_div").load("", function(event){
var data = new google.visualization.DataTable(test);
var options = {
width: 'auto',
height: '200',
title: 'Sales'
};
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
});
}
});
return false;
});
});
</script>
我找到了不正确的代码;如果我删除这段 .load 图表的代码,Datepicker 将在脚本之后工作:
$("#chart_div").load("", function(event){
var data = new google.visualization.DataTable(test);
var options = {
width: 'auto',
height: '200',
title: 'Sales'
};
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
});
我真的没有想法,非常感谢任何帮助。