事件内部代码。观察持续执行
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="finance.css"/>
<link rel="stylesheet" type="text/css" href="styles.css" />
<script type="text/javascript" src="prototype.js"></script>
<script type="text/javascript" src="scriptaculous.js"></script>
<script type="text/javascript" src="base64.js"></script>
<script type="text/javascript" src="canvas2image.js"></script>
<script type="text/javascript" src="canvastext.js"></script>
<script type="text/javascript" src="excanvas.js"></script>
<script type="text/javascript" src="flotr.js"></script>
<script type="text/javascript" src="HumbleFinance.js"></script>
<script type="text/javascript" src="prettify.js"></script>
<script type="text/javascript">
var priceData=[];
var dateData=[];
var NewdateData = [];
var NewData=[];
var date1 ;
var date2;
function callMe()
{
alert('dddw');
}
function drawChart(data)
{
for (var i = 0; i < data.jobs.length; i++) {
priceData.push([i, data.jobs[i].INCPU]);
dateData.push(data.jobs[i].Dater);
}
HumbleFinance.init('finance', priceData , dateData);
Event.observe(HumbleFinance.containers.summary, 'flotr:select', function (e) {
var area = e.memo[0];
xmin = Math.floor(area.x1);
xmax = Math.ceil(area.x2);
date1 = dateData[xmin];
date2 = dateData[xmax];
$('dateRange').update(dateData[xmin] + ' - ' + dateData[xmax]);
alert(date1);
alert(date2);
This two alerts are being called continously .
}
);
}
Event.observe(document, 'dom:loaded', function() {
new Ajax.Request('/HumblFin/Serv',
{
method:'get',
onSuccess: function(transport){
var data = transport.responseText.evalJSON();
drawChart(data);
},
onFailure: function(){ alert('Something went wrong...') }
});
});
</script>
</head>
<body>
<form id="sample">
<div id="finance">
<div id="dateRange">
</div>
</div>
</form>
</body>
</html>
Div DateRange仅更新一次,但两个警报正在连续执行
请帮助(就像div标签一样,我希望我的警报也想要一次)
解决方案
听起来像是在连续触发自定义事件'flotr:select'
。
查看提供的有限代码,我怀疑更新'dateRange'
元素会激发'flotr:select'
事件。
如果您有FireBug或Google Chrome,请在代码中放置断点并检查调用堆栈。
相关文章