What is the Difference between onclick and href="[removed]function name?

前端 未结 6 909
夕颜
夕颜 2021-02-10 11:55

Is there any difference between

1 : Link1

and

2 : 

        
6条回答
  •  生来不讨喜
    2021-02-10 12:56

    If your website requires Javascript in order to function correctly then Javascript in the href is best because it shows the link in the status bar and keeps the code compact. In the href also serves keyboard navigation without the mouse. If your website is required to function without Javascript then you have to use onclick so the href can have a link in it. Adding the action in a separate Javascript file fails to keep code & data bound tightly.

提交回复
热议问题