开发者

<script> tag at bottom causing $(document).ready to fail

I was following the snippets from html5boilerplate.com (as well as something that is recommended by yahoo) that we should put the scripts at the bottom of the page (of my site's main page).

I am also following SPI (Sin开发者_Python百科gle page interface) - meaning I will load the content area only via ajax for any new page visit.

My page structure is..

<body>
<header />
<div id="content" />
<footer />
</body>

Now issue is .. I load JQuery at the end of main page. But I need some javascript to get executed on the child page which would be loaded in content div. So if I write $(document).ready(..) in the child page, it will crib about "$ is not defined".

Any suggestions?


Put your jquery include into your header. Then it will work. As long you don't need a very high performance site you don't need such performance hacks. And you should understand how and why the hacks work before using them. If you really want to include jquery at the bottom of the script you have to put all your JS code below the jquery include.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜