开发者

altering onload event after body tag is printed, using jQuery .ready() in body of document

I have a tabbed page I inherited that works through a number of queries and the results determine what tabs are printed.

I want to implemen开发者_开发问答t some logic in PHP that will cause one tab or another to be the tab with focus when page load is completed.

Is it good practice to add a call to jQuery's .ready() at the closing body tag of the document?

Any advice most welcome.

Thanks.


$(document).ready(function() { }); can be put in script tags anywhere in your document. You can even have it occur multiple times.

Also, a shorter form of the above is:

$(function() { });

Passing a function to the jQuery object adds the function to the document's ready event.


As a general rule, it's recommended to put scripts at the bottom of the page, because otherwise they can hold up page rendering. You can read more at the Yahoo Best Practices guide.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜