[英]Javascript check to see if an event has already been fired or clicked
I have a function that needs to fire when I click on a chevron tab. 单击人字形标签时,我需要启动一个功能。 However I only need that function to fire that first time we load the page. 但是,我只需要在第一次加载页面时触发该函数。 How can I prevent it form firing every time the tab is clicked? 如何防止每次单击该标签时触发它?
$('#navi a').bind('click',function(e){
var $this = $(this);
var prevButton = current;
$this.closest('ul').find('li').removeClass('selected');
if ( $(this).attr('id') == 'tab2')
{
//fire function only once
}
});
Use: 采用:
var isalreadyclicked=false;
$('#navi a').bind('click',function(e){
var $this = $(this);
var prevButton = current;
$this.closest('ul').find('li').removeClass('selected');
if ( $(this).attr('id') == 'tab2')
{
if(!isalreadyclicked){
//fire function only once
isalreadyclicked=true;
}
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.