Why in Javascript event handler functions with parentheses?

后端 未结 4 2420
轻奢々
轻奢々 2020-12-09 12:25

Javascript gurus, look at this code:


        

        
4条回答
  •  忘掉有多难
    2020-12-09 13:23

    Because onclick="handler" isn't JavaScript. It's an attribute of your tag. Yes, if this were JavaScript, you'd be able to pass in the function itself, but it's not; you're assigning a statement to be executed on click.

    The statement executed by onclick="handler" basically does this:

    
    

    IE, nothing.

提交回复
热议问题