点击()发射多次 [英] click() firing multiple times

查看:134
本文介绍了点击()发射多次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的document.getElementById(VAL)。点击()调用一个click事件,但它一直射击多次。

I am using a document.getElementById("val").click() to invoke a click event, but it keeps firing multiple times.

下面我添加了事件处理程序

Here I add the eventHandler

try {
    //add mousedown event handler to navigation buttons
    addEventHandler(oPrevArrow, "mousedown", handlePrevDayClick);
    addEventHandler(oNextArrow, "mousedown", handleNextDayClick);
    addEventHandler(oLogout, "mousedown", handleLogoutClick);
} 
catch (err) {
}

在单击事件我正在执行一个自动点击

In the click event i am performing a "auto click"

function handleNextDayClick(e) {
    e = e || window.event;
    stopEvent(e);
    document.getElementById("btn_nextday").click();
}

我需要帮助弄清楚是什么使得它多次调用和可能的修正。

I need help to figure out what is making it call multiple times and a possible fix.

注:这是自动单击按钮调用在ASP.NET $ C $的方法C-背后

NB: the button that is auto-clicked calls a method in the ASP.NET Code-Behind

推荐答案

通常,当你有一个事件触发多次是因为该事件被连接到一次以上的元素,或者您是自动点击元素是一个孩子用相同的事件另一个元件附接。检查看看,如果他们互相缠绕,如果是这样,你将需要检测当前的目标是等于目标,以确保它只会发生一次。或者,你可以停止事件传播。

Usually when you have an event firing multiple times it is because the event is attached to an element more than once or the element you are auto clicking is a child of another element with the same event attached. Check to see if they are wrapped by each other and if so you will need to detect that the current target is equal to the target to make sure it only happens once. Or you can stop the event propagation.

这篇关于点击()发射多次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆