简体   繁体   English

仅在触发OnBlur事件之后才使OnMousedown事件被触发

[英]Make the OnMousedown event to be triggered only after the OnBlur event is triggered

We have a HTML screen that is formed by including the two sections below: 我们有一个HTML屏幕,其中包括以下两个部分:

  1. Footer - A bar with icons that includes an Update button. 页脚-带有图标的栏,其中包括“更新”按钮。 The update button has the onmousedown event associated with it. 更新按钮具有与之关联的onmousedown事件。 When the Update button is clicked the data present in the Body is saved in the database. 单击更新按钮时,正文中存在的数据将保存在数据库中。

  2. Body - HTML form with 2 input fields. 正文-具有2个输入字段的HTML表单。 Each of these fields has an onblur event associated with it. 每个字段都有一个与之关联的onblur事件。 The OnBlur actions consists of validations that must be run prior to running the Update action. OnBlur操作包含必须在运行Update操作之前运行的验证。

The problem is that sometimes the OnMouseDown event and henceforth the Update action is getting triggered prior to running the actions associated with the OnBlur events. 问题在于,有时会在运行与OnBlur事件关联的操作之前触发OnMouseDown事件以及此后的Update操作。 This is causing the validations that are bound with each field to be run after the Update is performed. 这将导致在执行更新后运行与每个字段绑定的验证。

This behaviour is occurring when I am on one of the Body fields (so the focus is on one of the Body section fields) and I click on the Update button. 当我在“正文”字段之一(因此焦点位于“正文”部分字段之一)上并且单击“更新”按钮时,就会发生此行为。

What are your suggestions to solve this problem? 您对解决这个问题有什么建议?

如果所有这些动作都应该一个接一个地发生,为什么不将所有动作都绑定到onClick?

You could use the onFocus event in various ways to ensure that the onBlur has completed. 您可以通过多种方式使用onFocus事件,以确保onBlur已完成。

I'm imagining something along the lines of throwing out onMouseDown and just putting a check in onFocus to see if the mouse button is currently down. 我正在想像一些东西,扔掉onMouseDown,只是检查onFocus,以查看鼠标按钮当前是否按下。 Check out this link for a decent implementation of how to check if the mouse button is down. 请查看此链接 ,以获取有关如何检查鼠标按钮是否按下的不错的实现。

Alternatively, however, I gotta mention that you might be getting yourself into trouble if you are only looking for onMouseDown. 但是,或者,我要提到的是,如果您只在寻找onMouseDown,则可能会遇到麻烦。 What happens if a user tabs over to the button and hits spacebar or enter? 如果用户跳到按钮上并按下空格键或回车,会发生什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM