0
我有一個從> - 選擇器使用datepicker通過som .ajax代碼,然後加載谷歌折線圖。PHP Datepicker鉻特定錯誤
我的問題是,在Chrome中,當單擊按鈕並且腳本已經運行一次時,輸入字段「from」和「to」在單擊時不會顯示日期選擇器。
如上所述,這只是在Chrome中,在IE和Firefox中,輸入字段會一直顯示Datepicker-popups。
這是我的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圖表中,日期選擇器將劇本後工作:
$("#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);
});
我真的離開這裏的想法,任何的幫助深表感謝。
只注意到,如果我在輸入欄中單擊快,而#chart_div仍在加載,我看到了日期選擇器......但後來消失了。 – Tronik
你可以發佈相關的HTML部分?如果可能的話添加一個jsFiddle,所以我們可以解決這個問題! :) – rusln