This is a fairly weird case, you can see the code here:
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- How to fix IE ClearType + jQuery opacity problem i
- void before promise syntax
- jQuery add and remove delay
This is a common Bug in Javascript. you can find many articles around internet specially on SO for event being fired twice. You can try something like this
And it's definitely Javascript problem because if you hit google and search for event fire twice you will see that Angular, Jquery and backbone etc all are somewhere firing events twice or even thrice. So, it's seems that it's javascript behind this. And off course if you search this with Mozilla Developers Network then you can see experts have also said so.
http://jsfiddle.net/Cc55g/
You need to call
event.preventDefault()
within your click handler. This prevents the default click action from being executed once your custom function runs. The second alert is occurring because the form is being submitted.you should not wrap
input
elements by using alabel
element, try this:http://jsfiddle.net/zpZtH/7/