这里是HTML代码,同时点击clearfix类的函数调用会发生,它会运行相同的函数4次。如何停止在JavaScript中一次又一次地调用相同的函数?
<div class="clearfix">
<ul id="dashboard-tab" class="nav nav-tabs pull-left">
<li class="active" isdashboardloaded="true">
<a data-toggle="tab" href="#dashboard_5" aria-expanded="true">DashLoadingLineChart</a>
</li>
<li class="" isdashboardloaded="true">
<a data-toggle="tab" href="#dashboard_6" aria-expanded="false">Zoom</a>
</li>
</ul>
</div>
JS功能
$(document).on('click','.clearfix',function(){
var dashId=$('.dashboardTabContent.active').attr('id');
var dash_ids = bu.angular.pageScope.dashboardCollection.collection;
var dashBoardUrl=event.target.href;
$.each(dashObj.widgetObj,function(widgetId,widgetObj){
clearWidget(widgetId,widgetObj.mode);
var widget_refresh_interval = widgetObj.refresh_interval;
//widgetInterval[widgetId] = 0;
clearInterval(widgetInterval[widgetId]);
bu.angular.pageScope.$digest();
widgetWiseReload(widgetId,dashId)
getWidgetData(widgetId,dashId,widgetObj,data_sources);
});
});
我需要运行这个功能只有一次,但它运行的2倍以上。
所以,你正在把一些东西放在一个循环中,并想知道为什么循环实际运行? – baao
使用['$ .one()'](http://api.jquery.com/one/)。这将附加处理程序,并且每个事件类型每个元素最多执行一次。 – Pugazh
@baao,完成循环后,它会再次回到相同的功能。 – Illusion