标签:
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 5 <title>无标题文档</title> 6 <script type="text/javascript" src="jquery-1.10.1.min.js"></script> 7 <script> 8 9 //方法函数化: 10 11 /*window.onload = function(){}; 12 13 $(function(){}); 14 15 function $(){} 16 17 innerHTML = 123; 18 19 html(123) 20 21 function html(){} 22 23 onclick = function(){}; 24 25 click(function(){}) 26 27 function click(){}*/ 28 29 /*window.onload = function(){ 30 var oDiv = document.getElementById(‘div1‘); 31 32 oDiv.onclick = function(){ 33 alert( this.innerHTML ); 34 }; 35 36 };*/ 37 38 $(function(){ 39 40 //var oDiv = $(‘#div1‘); 41 42 $(‘#div1‘).click(function(){ 43 44 alert( $(this).html() ); 45 46 }); 47 48 }); 49 50 $(‘ul‘).children().css(‘background‘,‘red‘); 51 52 </script> 53 </head> 54 55 <body> 56 <div id="div1">div</div> 57 58 </body> 59 </html>
方法函数化的一些小细节:
1、jQuery中的括号是特别多,特别重要的;
2、出现“=” 赋值的情况比较少,很多都是通过传参来实现;
所谓链式操作:就是指可以省略代码中原来赋值的那种形式,转而使用"."来连接。初学不推荐;
//alert( $(‘li‘).html() ); //当一组元素的时候,取值是一组中的第一个
$(‘li‘).html(‘hello‘); //当一组元素的时候,赋值是一组中的所有元素
标签:
原文地址:http://www.cnblogs.com/zhangxg/p/4737947.html