How does inline Javascript (in HTML) work?

前端 未结 6 712
醉酒成梦
醉酒成梦 2020-11-28 19:21

I know this is bad practice. Don\'t write code like this if at all possible.

Of course, we\'ll always find ourselves in situations where a clever snippet of inline

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-28 19:54

    You've got it nearly correct, but you haven't accounted for the this value supplied to the inline code.

    Click Me
    

    is actually closer to:

    Click Me
    
    

    Inline event handlers set this equal to the target of the event. You can also use anonymous function in inline script

    Click Me
    

提交回复
热议问题