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

前端 未结 3 1874
抹茶落季
抹茶落季 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:34

    I believe the javascript: prefix is left over from when there were many other script types bouncing around on the web (vbScript, for example) and in order to differentiate between them in HTML you needed to provide these prefixes.

    That being said, these tags do absolutely nothing in any browser other then IE anymore, and even in IE you generally can omit them.

    Also notice that this entire question is moot since you should be binding event handlers through javascript, not in HTML.

提交回复
热议问题