jQuery的三种写法
jQuery的三种写法
jQuery一共有三种写法,写法如下:
1 <script type="text/javascript" src="js/jquery-1.9.1.min.js"></script> 2 <script> 3 //第一种写法 4 $(function(){ 5 $("div").html(""); 6 // add your code here 7 }) 8 9 //第二种写法 10 $(document).ready(function(){ 11 $("div").html(""); 12 $("a").click(function(){ 13 // add your code here 14 }) 15 }) 16 17 //第三种写法 18 window.onload = function(){ 19 // add your code here 20 } 21 </script>
其中,第一种是简写方式,也是我比较喜欢用的一种