})(jQuery)
</script>
</body>
对, 就是利用js闭包的形式将js代码嵌入body,这段代码会自动执行,当然也可以直接嵌入js代码,这种方式要注意顺序问题,如下:
<body>
<div id=”test”>this is the content</div>
<script type=”text/javascript”>
alert($(“#test”).html());//I Can display the content
</script>
</body>
<body>
<script type=”text/javascript”>
alert($(“#test”).html());//I Can’t display the content
</script>
<div id=”test”>this is the content</div>
</body>
上面两段代码, 第二段代码当中因为只能解释到当前代码之前的DOM,而test并不存在于已经解析的DOM数.所以第二段代码无法正确显示.










