简体   繁体   中英

How to stop onclick, onblur, on* from happening

I have

<select onclick="alert('I was clicked!');" onblur="alert('Lost my focus :(');">

And I have jQuery listener that will click and blur this select if another element is clicked and blurred.

I have one problem and 1 question.

  1. Why does onclick, onblur, on* gets fired twice when another element triggers event?
  2. Is there a way to stop onclick, onblur, on* from firing?

Thank you!

JSFiddle http://jsfiddle.net/fallenboy/rUKyq/1/

EDIT:

As it seems, it cannot be achieved?

您可以使用preventDefault()函数停止默认行为

<select onclick="alert('I was clicked!'); return false;" onblur="alert('Lost my focus :(');">

要么

<select onclick="alert('I was clicked!');" onblur="alert('Lost my focus :('); return false;">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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