Why do you see colons while calling a javascript function in html sometimes?

前端 未结 3 1929
抹茶落季
抹茶落季 2021-02-20 15:12

A lot of the time I see people calling javascript functions using colon (:).

Like onclick=\"javascript:functionname();\"

The same function works wit

3条回答
  •  感动是毒
    2021-02-20 15:35

    javascript: prefix is extremely important when you put code to anchor href attribute:

    Anchor
    

    Whereas in inline event attributes (like onclick, onsubmit, onmouseover, etc.) javascript: prefix is not important.

    However, you should note that both approaches given here are not good to implement and you should use alternative ways (e.g as @Paul S. stated in the comments)

提交回复
热议问题