Javascript Flot绘制图表,然后无故重定向
我正在使用flot绘制一些数据。我在表单中输入开始和结束日期,然后检索要绘制的数据。图表会正确显示一段时间,但url会被重定向到同一页面,但会附加不存在的“?0=on&1=on&2=on&3=on&4=on&5=on”。这是我的密码:Javascript Flot绘制图表,然后无故重定向,javascript,jquery,flot,Javascript,Jquery,Flot,我正在使用flot绘制一些数据。我在表单中输入开始和结束日期,然后检索要绘制的数据。图表会正确显示一段时间,但url会被重定向到同一页面,但会附加不存在的“?0=on&1=on&2=on&3=on&4=on&5=on”。这是我的密码: <form onsubmit='formValidator()' > Start Date: <input type='text' id='date1' /><br /> End Date
<form onsubmit='formValidator()' >
Start Date: <input type='text' id='date1' /><br />
End Date: <input type='text' id='date2' /><br />
<input type='submit' value='Go' />
<div align="center"><div id="placeholder" style="width:80%; height: 700px"></div></div>
<p id="choices" style="color:#FFFFFF">Show:</p>
<script type="text/javascript" id="source">
function formValidator(){
// Make quick references to our fields
var d1 = document.getElementById('date1');
var d2 = document.getElementById('date2');
var msg = "Please enter the date in the format yyyymmdd. e.g. 20110609 for June 9, 2011";
// Check each input in the order that it appears in the form!
if(notEmpty(d1, msg)&& notEmpty(d2, msg) && isNumeric(d1, msg)&& isNumeric(d2, msg)&& lengthRestriction(d1, msg)&& lengthRestriction(d2, msg)){
$(function () {
var date1 = d1.value;
var date2 = d2.value;
/* foo1-6 are arrays that get their assigned values here */
var datasets = [
{label: "Foo1", data: foo1 },
{label: "Foo2", data: foo2 },
{label: "Foo3", data: foo3 },
{label: "Foo4", data: foo4 },
{label: "Foo5", data: foo5 },
{label: "Foo6", data: foo6 }
];
// hard-code color indices to prevent them from shifting as
// options are turned on/off
var i = 0;
$.each(datasets, function(key, val) {
val.color = i;
++i;
});
// insert checkboxes
var choiceContainer = $("#choices");
$.each(datasets, function(key, val) {
choiceContainer.append('<br/><input type="checkbox" name="' + key +
'" checked="checked" id="id' + key + '">' +
'<label for="id' + key + '">'
+ val.label + '</label>');
});
choiceContainer.find("input").click(plotAccordingToChoices);
function plotAccordingToChoices() {
var data = datasets;
choiceContainer.find("input:checked").each(function () {
var key = $(this).attr("name");
if (key && datasets[key])
data.push(datasets[key]);
});
if (data.length > 0) {
var options = {
legend: {
backgroundColor: "#000000",
backgroundOpacity: 0.9,
labelFormatter: function(label,series) {
return "<div style=color:#FFFFFF>" + label + "</div>";
}
},
yaxis: { min: 0 },
}
};
$.plot($("#placeholder"), data, options);
}
plotAccordingToChoices();
});
}
}
开始日期:
结束日期:
显示:
函数formValidator(){
//快速引用我们的字段
var d1=document.getElementById('date1');
var d2=document.getElementById('date2');
var msg=“请以yyyymmdd格式输入日期,例如2011年6月9日的20110609”;
//按表单中显示的顺序检查每个输入!
if(notEmpty(d1,msg)&¬Empty(d2,msg)&&isNumeric(d1,msg)&&isNumeric(d2,msg)&&lengthRestriction(d1,msg)&&lengthRestriction(d2,msg)){
$(函数(){
var date1=d1.0的值;
var date2=d2.0值;
/*foo1-6是在此处获取其赋值的数组*/
变量数据集=[
{标签:“Foo1”,数据:Foo1},
{标签:“Foo2”,数据:Foo2},
{标签:“Foo3”,数据:Foo3},
{标签:“Foo4”,数据:Foo4},
{标签:“Foo5”,数据:Foo5},
{标签:“Foo6”,数据:Foo6}
];
//硬编码颜色索引,以防止它们随着时间的推移而移动
//选项处于打开/关闭状态
var i=0;
$。每个(数据集、函数(键、值){
val.color=i;
++一,;
});
//插入复选框
var choiceContainer=$(“#选项”);
$。每个(数据集、函数(键、值){
choiceContainer.append(“
”+
''
+val.label+“”);
});
choiceContainer.find(“input”)。单击(根据选项绘制);
功能图根据目录()绘制{
var数据=数据集;
choiceContainer.find(“输入:选中”)。每个(函数(){
var key=$(this.attr(“name”);
if(键和数据集[键])
数据推送(数据集[键]);
});
如果(data.length>0){
变量选项={
图例:{
背景颜色:“000000”,
背景不透明度:0.9,
labelFormatter:函数(标签,系列){
返回“+标签+”;
}
},
yaxis:{min:0},
}
};
$.plot($(“#占位符”)、数据、选项);
}
绘图依据目录();
});
}
}
必须得出结论,页面上还有其他一些javascript导致了这种行为:您是否已将页面缩减为只有jquery、flot和数据源,并确保没有其他用户提供的javascript导致重新加载?flot库中没有任何东西会导致自动重新加载,所以我猜这是部署应用程序的框架的某个工件。我们使用jQuery UI Datepicker进行日期选择,解决了这个问题。仍然不知道为什么会出现刷新问题,但很高兴它能正常工作。因此,切换到jQueryUIDatePicker解决了这个问题(如果是的话,您以前使用了什么)?