开发者

Do inline Javascript events decrease web page loading performance?

开发者 https://www.devze.com 2023-03-21 22:23 出处:网络
Doesinline Javascript code like this below: <div onclick=\'javascript:some_function();\'></div>

Does inline Javascript code like this below:

<div onclick='javascript:some_function();'></div>

grow up web page's loading time in an开发者_StackOverflowy way?


Yes, it does.

The browser must fire up a separate Javascript parser for each attribute.

It is more efficient to bind the events to functions using attachEvent / addEventHandler, or, more easily, jQuery.


On an unrelated note, you shouldn't use javascript: in an event attribute (aside from the fact that you shouldn't use event attributes at all). It's just an unused label.
In href attributes, the javascript: protocol allows you to create a URI that executes Javascript. However, event attributes take a string of Javascript code, not a URI.

0

精彩评论

暂无评论...
验证码 换一张
取 消