jQuery¼¼Êõ

[jQueryѧϰϵÁжþ ]2(2)

×ÖºÅ+ ×÷ÕߣºH5Ö®¼Ò À´Ô´£ºH5Ö®¼Ò 2018-02-16 09:29 ÎÒÒªÆÀÂÛ( )

//ÔÚµ±Ç°Ò³ÃæÄÚ×·¼Ó»»ÐбêÇ©ºÍÖ¸¶¨µÄHTMLÄÚÈÝfunction w( html ){document.body.innerHTML += "br/" + html;}var x = { name:"CodeMan" };var y = { age: 18 };var z = { site: "http://www.cnblogs.com/wang-meng/

¼¼Êõ·ÖÏíͼƬ

//ÔÚµ±Ç°Ò³ÃæÄÚ×·¼Ó»»ÐбêÇ©ºÍÖ¸¶¨µÄHTMLÄÚÈÝ function w( html ){ document.body.innerHTML += "<br/>" + html; } var x = { name:"CodeMan" }; var y = { age: 18 }; var z = { site: "http://www.cnblogs.com/wang-meng/" }; var obj = $.extend( x, y, z ); w( obj === x ); // true w( obj.name ); // CodeMan w( obj.age ); // 18 w( obj.site ); //

¼¼Êõ·ÖÏíͼƬ


(2)jQuery.makeArray( obj )
º¯ÊýÓÃÓÚ½«Ò»¸öÀàÊý×é¶ÔÏóת»»ÎªÕæÕýµÄÊý×é¶ÔÏó¡£
ÀàÊý×é¶ÔÏóÊǷdz£³£¼ûµÄ: ÀýÈçÎÒÃǾ­³£Ê¹ÓõÄjQuery¶ÔÏ󡢺¯ÊýÄÚµÄarguments¶ÔÏ󣬶¼ÊÇÀàÊý×é¶ÔÏó¡£
jQuery.makeArray()º¯Êý: ÎÒÃÇ¿ÉÒÔ½«ÀàÊý×é¶ÔÏóת»»ÎªÒ»¸öÕæÕýµÄÊý×é¶ÔÏ󣬴ӶøʹÓÃÊý×é¶ÔÏóµÄÄÚÖ÷½·¨¡£
ʾÀýÈçÏÂ:

¼¼Êõ·ÖÏíͼƬ

<p>¶ÎÂä1</p> <p>¶ÎÂä2</p> //ÔÚµ±Ç°Ò³ÃæÄÚ×·¼Ó»»ÐбêÇ©ºÍÖ¸¶¨µÄHTMLÄÚÈÝ function w( html ){ document.body.innerHTML += "<br/>" + html; } // jQuery¶ÔÏóÒ²ÊÇÒ»¸öÀàÊý×é¶ÔÏó var $p = $("p"); var arr1 = $.makeArray( $p ); w( $p instanceof Array ); // false w( arr1 instanceof Array ); // true // NodeList¶ÔÏóÒ²ÊÇÒ»¸öÀàÊý×é¶ÔÏó var p = document.getElementsByTagName("p"); var arr2 = $.makeArray( p ); w( p instanceof Array ); // false w( arr2 instanceof Array ); // true function foo(a, b){ //arguments¶ÔÏóÒ²ÊÇÒ»¸öÀàÊý×é¶ÔÏó //argumentsÊÇÊÕµ½µÄʵ²Î¸±±¾£¬ var arr3 = $.makeArray( arguments ); w( arguments instanceof Array ); // false w( arr3 instanceof Array ); // true } foo(1, 2);

¼¼Êõ·ÖÏíͼƬ

 

(3)jQuery.inArray( value, array )
value: ÈÎÒâÀàÐÍÓÃÓÚ²éÕÒµÄÖµ¡£
array: ArrayÀàÐÍÖ¸¶¨±»²éÕÒµÄÊý×é¡£
º¯ÊýÓÃÓÚÔÚÊý×éÖÐËÑË÷Ö¸¶¨µÄÖµ£¬²¢·µ»ØÆäË÷ÒýÖµ¡£Èç¹ûÊý×éÖв»´æÔÚ¸ÃÖµ£¬Ôò·µ»Ø -1¡£

ʾÀýÈçÏÂ:

¼¼Êõ·ÖÏíͼƬ

//ÔÚµ±Ç°Ò³ÃæÄÚ×·¼Ó»»ÐбêÇ©ºÍÖ¸¶¨µÄHTMLÄÚÈÝ function w( html ){ document.body.innerHTML += "<br/>" + html; } var arr = [ 10, 25, 3, 0, -3 ]; w( $.inArray( 25, arr ) ); // 1 w( $.inArray( -3, arr ) ); // 4 w( $.inArray( 10, arr ) ); // 0 // Êý×éÖÐûÓÐ99 w( $.inArray( 99, arr ) ); // -1 // Êý×éÖÐÓÐÊý×Ö10£¬µ«ÊÇûÓÐ×Ö·û´®"10" w( $.inArray( "10", arr ) ); // -1

¼¼Êõ·ÖÏíͼƬ


(4)jQuery.merge( first, second )
ºÏ²¢Á½¸öÊý×é
·µ»ØµÄ½á¹û»áÐ޸ĵÚÒ»¸öÊý×éµÄÄÚÈÝ¡ª¡ªµÚÒ»¸öÊý×éµÄÔªËغóÃæ¸ú×ŵڶþ¸öÊý×éµÄÔªËØ¡£
Ҫȥ³ýÖظ´ÏÐèҪʹÓÃ$.unique()

ºÏ²¢Á½¸öÊý×éµ½µÚÒ»¸öÊý×éÉÏ: $.merge( [0,1,2], [2,3,4] ) ½á¹û: [0,1,2,2,3,4]

 

(5)jQuery.unique( array )
ɾ³ýÊý×éÖÐÖظ´ÔªËØ¡£Ö»´¦Àíɾ³ýDOMÔªËØÊý×飬¶ø²»ÄÜ´¦Àí×Ö·û´®»òÕßÊý×ÖÊý×é¡£

$.unique( [0,1,2], [2,3,4] ) ½á¹û: [0,1,2,3,4]

 

(6)arguments(Ôö¼ÓÄÚÈÝ)
Javascript²¢Ã»ÓÐÖØÔغ¯ÊýµÄ¹¦ÄÜ£¬µ«ÊÇArguments¶ÔÏóÄܹ»Ä£ÄâÖØÔØ¡£JavascripÖÐÿ¸öº¯Êý¶¼»áÓÐÒ»¸öArguments¶ÔÏóʵÀýarguments£¬ËüÒýÓÃן¯ÊýµÄʵ²Î£¬¿ÉÒÔÓÃÊý×éϱêµÄ·½Ê½"[]"ÒýÓÃargumentsµÄÔªËØ¡£
arguments.lengthΪº¯Êýʵ²Î¸öÊý£¬arguments.calleeÒýÓú¯Êý×ÔÉí¡£

ʾÀýÈçÏÂ:

¼¼Êõ·ÖÏíͼƬ

function test(){ // Ñ­»·Êä³öµ÷Óõ±Ç°º¯Êýʱ´«ÈëµÄ²ÎÊý for(var n = 0; n < arguments.length; n++){ document.write( arguments[n] + "|"); } document.write(¡®<br>¡®); // Êä³ö»»Ðзû½øÐÐÇø·Ö }; test(); // (¿Õ×Ö·û´®) test("Code", "http://www.cnblogs.com/wang-meng/", 12, true); // Code||12|true| test("ÕÅÈý", false, 12.315); // ÕÅÈý|false|12.315| function foo(){ // argumentsÇ°Ò²¿ÉÒÔ¼ÓÉϺ¯ÊýÃû³Æ for(var n = 0; n < foo.arguments.length; n++){ document.write( foo.arguments[n] + "|"); } document.write(¡®<br>¡®); }; foo("Hello", "World"); // Hello|World| // ʹÓÃarguments¶ÔÏóʵÏÖÈÎÒâ¶à¸öÊýµÄÇóºÍ function sum(){ var sum = arguments[0]; for(var n = 1; n < arguments.length; n++){ sum += arguments[n]; } return sum; } document.writeln( sum() ); // undefined document.writeln( sum( 1, 5 ) ); // 6 document.writeln( sum( 1, 212, 21, -14, 23 ) ); // 243

¼¼Êõ·ÖÏíͼƬ

 

5£¬ÆäËû
ÆäËû¸ü¶à¹ØÓÚÊý×éµÄ²Ù×÷Çë²é¿´: W3School JS Array

ÒÔÉÏÄÚÈݽÔÊÇ×Ô¼ºÑ§Ï°ÖÐÕûÀí³öÀ´µÄÄÚÈÝ, ÈçÓÐç¢Â©Çë´ó¼Ò¿´µ½¿ÉÒÔÌáÐÑÒ»ÏÂ. ÕûÀí¼Ç¼ÔÚÕâÀïËãÊǶÔ×Ô¼ºÑ§Ï°µÄÒ»¸ö×ܽá, ¸øÈÕºóµÄÍü¼ÇµÄ×Ô¼ºÒ»¸ö²Î¿¼.

Ó¢ÓïСÌùÊ¿£º
Good for you¡£
ºÃ°¡£¡×öµÃºÃ£¡
Great minds think alike£¡
Ó¢ÐÛËù¼ûÂÔͬ£¡
Have a nice day.
×£Äã½ñÌìÓä¿ì¡£
Have butterflies in one¡®s stomach.
½ôÕÅ¡£
He¡®s been everywhere.
Ëûµ½´¦¶¼È¥¹ýÁË¡£
He hit the ceiling at the news.
ËûÌýµ½ÄÇÏûÏ¢±©ÌøÈçÀ×/´ó·¢À×öª¡£
His argument doesn¡®t hold water.
ËûµÄÂÛµãÕ¾²»×¡½Å¡£
How do I address you?
ÎÒÔõô³ÆºôÄ㣿

¡¡

1.±¾Õ¾×ñÑ­ÐÐÒµ¹æ·¶£¬ÈκÎתÔصĸå¼þ¶¼»áÃ÷È·±ê×¢×÷ÕߺÍÀ´Ô´£»2.±¾Õ¾µÄÔ­´´ÎÄÕ£¬ÇëתÔØʱÎñ±Ø×¢Ã÷ÎÄÕÂ×÷ÕߺÍÀ´Ô´£¬²»×ðÖØÔ­´´µÄÐÐΪÎÒÃǽ«×·¾¿ÔðÈΣ»3.×÷ÕßͶ¸å¿ÉÄܻᾭÎÒÃDZ༭Ð޸Ļò²¹³ä¡£

Ïà¹ØÎÄÕÂ
  • jQuery»ù´¡½Ì³Ì(µÚËÄ°æ)µÚ3ÕÂÁ·Ï°:

    jQuery»ù´¡½Ì³Ì(µÚËÄ°æ)µÚ3ÕÂÁ·Ï°:

    2018-02-12 12:03

  • jquery×óÓÒÕÛµþ¿ò

    jquery×óÓÒÕÛµþ¿ò

    2017-11-22 14:00

  • JQueryµÄdeferred¶ÔÏóѧϰ×ܽá

    JQueryµÄdeferred¶ÔÏóѧϰ×ܽá

    2017-11-15 11:17

  • ·Ç·¨¼¯×Ê°¸¼þ¡¢½ð¶îÊ×ÏÖ¡°Ë«½µ¡± ÏÂÔÂÆð¿ªÕ¹×¨ÏîÅŲé

    ·Ç·¨¼¯×Ê°¸¼þ¡¢½ð¶îÊ×ÏÖ¡°Ë«½µ¡± ÏÂÔÂÆð¿ªÕ¹×¨ÏîÅŲé

    2017-11-09 10:01

ÍøÓѵãÆÀ
¸