开发者

Is it possible to see a difference between mouse click and obj.click()?

开发者 https://www.devze.com 2023-01-03 03:36 出处:网络
Lets say there is a form with a submit button. I found out that using javascript i can call the click() method for input elements in Firefox which would simulate the 开发者_StackOverflowmouse click on

Lets say there is a form with a submit button. I found out that using javascript i can call the click() method for input elements in Firefox which would simulate the 开发者_StackOverflowmouse click on that element.

But then, i got this question, can you detect if button was clicked with real computer mouse, or .click() method?

Thank you


You can trigger a test using onmousedown from the element in question.

Keep in mind the following though:

  • If your type="submit", you can use the same function that envokes .click() to just submit the form like ~formName.submit();
  • If type="button" and for some reason you have an onclick event handler that submits the form, your onclick events will be invoked whether you call .click() or actually click the button.
  • onmousedown events will not be called using .click().
0

精彩评论

暂无评论...
验证码 换一张
取 消