erichua 发表于 2013-1-23 02:51:06

JQuery读书笔记--JQuery库中的Type技巧总结-3

7.Options
JQuery中大量的使用Options作为函数内定义。
//没有option也可以工作 $("#myform").ajaxForm();//添加更明确 $("#myform").ajaxForm({   url: "mypage.php",   type: "POST" });


8.Array
//array 定义 var x = []; var y = ;//注意array的 type of 可不是array 是objecttypeof []; // "object" typeof ; // "object"//读取内容 x = 1; y // 3 //循环 for (var i = 0; i < a.length; i++) {   // Do something with a }//优化方法,可以提高性能哦 for (var i = 0, j = a.length; i < j; i++) {   // Do something with a }//另外一种方法,但包含0和空字符时不能使用。 for (var i = 0, item; item = a; i++) {   // Do something with item }//jquery方法 var x = ; jQuery.each(x, function(index, value) {   console.log("index", index, "value", value); });//数组添加内容 var x = []; x.push(1); x = 2; x // 1, 2//array 方法 var x = ; x.reverse() // x.join(" – ") // "2 - 1 - 3 - 0" x.pop() // x.unshift(-1) // [-1, 2, 1, 3] x.shift() // x.sort() // x.splice(1, 2) // // 数组永远为true ![] // false//明确数组类型Array<Type> Notation

9.Map
就像Java中的colloection
{'key[]':['valuea','valueb']}

10.function
Js中function可以有name也可为anonymous
//有name的function named() {}//anonymousvar handler = function() {}//jquery 中callback经常用anonymous函数,一次性 $(document).ready(function() {}); $("a").click(function() {}); $.ajax({   url: "someurl.php",   success: function() {} });//注意fucntion的参数function log(x) {console.log(typeof x, arguments.length);}log(); // "undefined", 0log(1); // "number", 1log("1", "2", "3"); // "string", 3 以最后一个为准//function中this的意义$(document).ready(function() {// this就是 window.document});$("a").click(function() {// this 可不是a});//function的call 和applyfunction scope() {console.log(this, arguments.length);}scope() // window, 0scope.call("foobar", ); // "foobar", 1 call将参数作为一个参数传入scope.apply("foobar", ); // "foobar", 2 apply则将参数作为一个数组传入//function中参数范围 // global var x = 0; (function() {   // private   var x = 1;   console.log(x); // 1 })(); console.log(x); // 0//括则号的作用//c1就是一个模板var c1 = function() {var counter = 0;return {    increment: function() {      counter++;    },    print: function() {      console.log(counter);    }}};var ss=new c1();ss.increment();ss.increment();ss.print();   //2//同样作用function create() {var counter = 0;return {    increment: function() {      counter++;    },    print: function() {      console.log(counter);    }}}var c = create();c.increment();c.print(); // 1//function 中的aop用法比java简单多了(function() {// log all calls to setArrayvar proxied = jQuery.fn.setArray;//先保存jQuery.fn.setArray = function() {    console.log(this, arguments);   //aop    return proxied.apply(this, arguments); //再调用};})();
页: [1]
查看完整版本: JQuery读书笔记--JQuery库中的Type技巧总结-3