开发者

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

开发者 https://www.devze.com 2023-03-15 15:35 出处:网络
I have a tabbed page I inherited that works through a number of queries and the results determine what tabs are printed.

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

精彩评论

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