Checkboxes are being checked before click handler is even called

前端 未结 2 1381
名媛妹妹
名媛妹妹 2021-01-15 13:47

I have the following snippets: http://jsfiddle.net/L7rne/5/ and http://jsfiddle.net/L7rne/6/

It turns out that if you pause execution of the script in the click even

相关标签:
2条回答
  • 2021-01-15 14:10

    By time the event handler fires, the event has already taken place, and the browser is re-rendering in response. If the handler gets suspended, then the browser completes the work because nothing prevented it.

    Its like calling the police to a bank robbery, and they are in a traffic accident on the way. The robbers get away. The deed is done.

    0 讨论(0)
  • 2021-01-15 14:31

    not sure I'm understanding the problem. why wouldn't it be the right behaviour?

    seriously, let's say you write some code that shows/hides a div based on whether a checkbox is ticked or not.

    so, you write an onclick. if the checkbox is unticked, and then you click it, what do you think should be done to the div? obviously, you would expect the event to find the checkbox to be checked.

    0 讨论(0)
提交回复
热议问题