开发者

Do inline Javascript events decrease web page loading performance?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜