jQuery¼¼Êõ

ÖÐÎÄjqueryÈëÃűضÁµÄ½Ì³Ì(3)

×ÖºÅ+ ×÷ÕߣºH5Ö®¼Ò À´Ô´£ºH5Ö®¼Ò 2015-09-25 12:15 ÎÒÒªÆÀÂÛ( )

ËäÈ»ÕâЩÀý×ÓÒ²¿ÉÒÔ²»Ê¹ÓÃAJAXÀ´ÊµÏÖ£¬µ«ÏÔʾÎÒÃDz»»áÄÇô×ö£¬ÎÒÃÇÓÃjQueryÉú³ÉÒ»¸öDIVÈÝÆ÷£¬IDÊÇ"rating". $(document).ready(function() {// generate markupvar ratingMarkup = ["Please rate: "];for(var i=1;

ËäÈ»ÕâЩÀý×ÓÒ²¿ÉÒÔ²»Ê¹ÓÃAJAXÀ´ÊµÏÖ£¬µ«ÏÔʾÎÒÃDz»»áÄÇô×ö£¬ÎÒÃÇÓÃjQueryÉú³ÉÒ»¸öDIVÈÝÆ÷£¬IDÊÇ"rating".

$(document).ready(function() { // generate markup var ratingMarkup = ["Please rate: "]; for(var i=1; i <= 5; i++) { ratingMarkup[ratingMarkup.length] = "<a href='#'>" + i + "</a> "; } // add markup to container and applier click handlers to anchors $("#rating").append( ratingMarkup.join('') ).find("a").click(function(e) { e.preventDefault(); // send requests $.post("rate.php", {rating: $(this).html()}, function(xml) { // format result var result = [ "Thanks for rating, current average: ", $("average", xml).text(), ", number of votes: ", $("count", xml).text() ]; // output result $("#rating").html(result.join('')); } ); }); });

Õâ¶Î´úÂëÉú³ÉÁË5¸öÁ´½Ó£¬²¢½«ËüÃÇ×·¼Óµ½idΪ"rating"ÈÝÆ÷ÖУ¬µ±ÆäÖÐÒ»¸öÁ´½Ó±»µã»÷ʱ£¬¸ÃÁ´½Ó±êÃ÷µÄ·ÖÊý¾Í»áÒÔrating²ÎÊýÐÎʽ·¢Ë͵½rate.php£¬È»ºó£¬½á¹û½«ÒÔXMLÐÎʽ»á´Ó·þÎñÆ÷¶Ë´«»ØÀ´£¬Ìí¼Óµ½ÈÝÆ÷ÖУ¬Ìæ´úÕâЩÁ´½Ó¡£

²»Ê¹ÓÃjavascriptʵÏÖµÄÀý×Ó¿ÉÒÔ·ÃÎÊ softonic.de µã»÷ "Kurz bewerten!"

¸ü¶àµÄAJAX·½·¨¿ÉÒÔ´ÓÕâÀï ÕÒµ½£¬»òÕß¿´¿´APIÎĵµ ÏÂÃæµÄAJAX filed under AJAX.

£¨×¢£ºÕâ¸öÔÚÏßʵÀý´Ó¹úÄÚ·ÃÎÊ»¹ÊDZȽÏÂýµÄ£¬µã»÷ºóÒªµÈÒ»»á¶ù²ÅÄÜ¿´µ½½á¹û£¬¿ÉÒÔ¿¼ÂǶÔËü½øÐÐÐ޸ģ¬±ÈÈç¼ÓÉÏloading£¬Í¶Æ±ºó¼ÓÉÏÔÙͶƱµÄ·µ»ØÁ´½ÓµÈ¡£´ËÍ⣬Õâ¸öÀý×ÓÖл¹ÊÇÓкܶàÐèÒª½øÒ»²½Ïû»¯µÄµØ·½£¬¿´²»¶®µÄµØ·½Çë²Î¿¼APIÎĵµ¡££©

Ò»¸öÔÚʹÓÃAJAXÔØÈëÄÚÈÝʱ¾­³£·¢ÉúµÄÎÊÌâÊÇ£ºµ±ÔØÈëÒ»¸öʼþ¾ä±úµ½Ò»¸öHTMLÎĵµÊ±£¬»¹ÐèÒªÔÚÔØÈëÄÚÈÝÉÏÓ¦ÓÃÕâЩʼþ£¬Äã²»µÃ²»ÔÚÄÚÈݼÓÔØÍê³ÉºóÓ¦ÓÃÕâЩʼþ¾ä±ú£¬ÎªÁË·ÀÖ¹´úÂëÖظ´Ö´ÐУ¬Äã¿ÉÄÜÓõ½ÈçÏÂÒ»¸öfunction:

// lets use the shortcut $(function() { var addClickHandlers = function() { $("a.clickMeToLoadContent").click(function() { $("#target").load(this.href, addClickHandlers); }); }; addClickHandlers(); });

ÏÖÔÚ£¬addClickHandlersÖ»ÔÚDOMÔØÈëÍê³ÉºóÖ´ÐÐÒ»´Î£¬ÕâÊÇÔÚÓû§Ã¿´Îµã»÷¾ßÓÐclickMeToLoadContent Õâ¸öÑùʽµÄÁ´½Ó²¢ÇÒÄÚÈݼÓÔØÍê³Éºó.

Çë×¢ÒâaddClickHandlersº¯ÊýÊÇ×÷Ϊһ¸ö¾Ö²¿±äÁ¿¶¨ÒåµÄ£¬¶ø²»ÊÇÈ«¾Ö±äÁ¿(È磺function addClickHandlers() {...})£¬ÕâÑù×öÊÇΪÁË·ÀÖ¹ÓëÆäËûµÄÈ«¾Ö±äÁ¿»òÕߺ¯ÊýÏà³åÍ».

ÁíÒ»¸ö³£¼ûµÄÎÊÌâÊǹØÓڻص÷(callback)µÄ²ÎÊý¡£Äã¿ÉÒÔͨ¹ýÒ»¸ö¶îÍâµÄ²ÎÊýÖ¸¶¨»Øµ÷µÄ·½·¨£¬¼òµ¥µÄ°ì·¨Êǽ«Õâ¸ö»Øµ÷·½·¨°üº¬ÔÚÒ»¸öÆäËüµÄfunctionÖÐ:

// get some data var foobar = ...; // specify handler, it needs data as a paramter var handler = function(data) { ... }; // add click handler and pass foobar! $('a').click( function(event) { handler(foobar); } ); // if you need the context of the original handler, use apply: $('a').click( function(event) { handler.apply(this, [foobar]); } );

Óõ½¼òµ¥µÄAJAXºó£¬ÎÒÃÇ¿ÉÒÔÈÏΪÒѾ­·Ç³£Ö®¡°web2.0¡±ÁË£¬µ«Êǵ½ÏÖÔÚΪֹ£¬ÎÒÃÇ»¹È±ÉÙһЩ¿áìŵÄЧ¹û¡£ÏÂÒ»½Ú½«»á̸µ½ÕâЩЧ¹û.

Animate me(ÈÃÎÒÉú¶¯ÆðÀ´):ʹÓÃFX

һЩ¶¯Ì¬µÄЧ¹û¿ÉÒÔʹÓà show() ºÍ hide()À´±íÏÖ:

$(document).ready(function() { $("a").toggle(function() { $(".stuff").hide('slow'); }, function() { $(".stuff").show('fast'); }); });

Äã¿ÉÒÔÓë animate()ÁªºÏÆðÀ´´´½¨Ò»Ð©Ð§¹û,ÈçÒ»¸ö´ø½¥ÏԵĻ¬¶¯Ð§¹û:

$(document).ready(function() { $("a").toggle(function() { $(".stuff").animate({ height: 'hide', opacity: 'hide' }, 'slow'); }, function() { $(".stuff").animate({ height: 'show', opacity: 'show' }, 'slow'); }); });

ºÜ¶à²»´íµÄЧ¹û¿ÉÒÔ·ÃÎÊinterface plugin collection. Õâ¸öÕ¾µãÌṩÁ˺ܶàdemosºÍÎĵµ

ÕâЩЧ¹û²å¼þÊÇλÓÚjQuery²å¼þÁбíµÄÇ°ÃæµÄ£¬µ±È»Ò²ÓкܶàÆäËûµÄ²å¼þ£¬±ÈÈçÎÒÃÇÏÂÒ»Õ½²µ½µÄ±í¸ñÅÅÐò²å¼þ¡£

Sort me(½«ÎÒÓÐÐò»¯):ʹÓÃtablesorter²å¼þ(±í¸ñÅÅÐò)

Õâ¸ö±í¸ñÅÅÐò²å¼þÄÜÈÃÎÒÃÇÔÚ¿Í»§¶Ë°´Ä³Ò»ÁнøÐÐÅÅÐò£¬ÒýÈëjQueryºÍÕâ¸ö²å¼þµÄjsÎļþ£¬È»ºó¸æËß²å¼þÄãÏëÒªÄĸö±í¸ñÓµÓÐÅÅÐò¹¦ÄÜ¡£

Òª²âÊÔÕâ¸öÀý×Ó£¬ÏÈÔÚstarterkit.htmlÖмÓÉÏÏñÏÂÃæÕâÒ»ÐеĴúÂ룺

<script src="lib/jquery.tablesorter.js" type="text/javascript"></script>

È»ºó¿ÉÒÔÕâÑùµ÷Óò»×Å:

$(document).ready(function() { $("#large").tableSorter(); });

ÏÖÔÚµã»÷±í¸ñµÄµÚÒ»ÐÐheadÇøÓò£¬Äã¿ÉÒÔ¿´µ½ÅÅÐòµÄЧ¹û£¬Ôٴεã»÷»á°´µ¹¹ýÀ´µÄ˳Ðò½øÐÐÅÅÁС£

Õâ¸ö±í¸ñ»¹¿ÉÒÔ¼ÓһЩͻ³öÏÔʾµÄЧ¹û£¬ÎÒÃÇ¿ÉÒÔ×öÕâÑùÒ»¸ö¸ôÐб³¾°É«£¨°ßÂíÏߣ©Ð§¹û:

$(document).ready(function() { $("#large").tableSorter({ stripingRowClass: ['odd','even'], // Class names for striping supplyed as a array. stripRowsOnStartUp: true // Strip rows on tableSorter init. }); });

¹ØÓÚÕâ¸ö²å¼þµÄ¸ü¶àÀý×ÓºÍÎĵµ¿ÉÒÔÔÚ tablesorterÊ×Ò³ÕÒµ½.

¼¸ºõËùÓеÄÌؼþ¶¼ÊÇÕâÑùÓõÄ:ÏÈinclude²å¼þµÄjsÎļþ,È»ºóÔÚijЩԪËØÉÏʹÓòå¼þ¶¨ÒåµÄ·½·¨,µ±È»Ò²ÓÐһЩ²ÎÊýÑ¡ÏîÊÇ¿ÉÒÔÅäÖõÄ

¾­³£¸üеIJå¼þÁбí¿ÉÒÔ´ÓjQuery¹Ù·½Õ¾ on the jQuery siteÕÒµ½.

µ±Äã¸ü¾­³£µØʹÓÃjQueryʱ,Äã»á·¢ÏÖ½«Äã×Ô¼ºµÄ´úÂë´ò°ü³É²å¼þÊǺÜÓÐÓô¦µÄ,ËüÄÜ·½±ãµØÈÃÄãµÄ¹«Ë¾»òÕßÆäËûÈ˽øÐÐÖØÓÃ.ÏÂÒ»ÕÂÎÒÃǽ«Ì¸µ½ÈçºÎ¹¹½¨Ò»¸ö×Ô¼ºµÄ²å¼þ.

Plug me:ÖÆ×÷×Ô¼ºµÄ²å¼þ

дһ¸ö×Ô¼ºµÄjQuery²å¼þÊǷdz£ÈÝÒ×µÄ,Èç¹ûÄã°´ÕÕÏÂÃæµÄÔ­ÔòÀ´×ö,¿ÉÒÔÈÃÆäËûÈËÒ²ÈÝÒ׵ؽáºÏʹÓÃÄãµÄ²å¼þ.

  • ΪÄãµÄ²å¼þÈ¡Ò»¸öÃû×Ö,ÔÚÕâ¸öÀý×ÓÀïÃæÎÒÃǽÐËü"foobar".
  • ´´½¨Ò»¸öÏñÕâÑùµÄÎļþ:jquery.[yourpluginname].js,±ÈÈçÎÒÃÇ´´½¨Ò»¸öjquery.foobar.js
  • ´´½¨Ò»¸ö»ò¸ü¶àµÄ²å¼þ·½·¨,ʹÓü̳ÐjQuery¶ÔÏóµÄ·½Ê½,Èç: jQuery.fn.foobar = function() { // do something };
  • ¿ÉÑ¡µÄ:´´½¨Ò»¸öÓÃÓÚ°ïÖú˵Ã÷µÄº¯Êý,Èç: jQuery.fooBar = { height: 5, calculateBar = function() { ... }, checkDependencies = function() { ... } };

    ¡¡

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

    Ïà¹ØÎÄÕÂ
    • 7¸öÓÐÓõÄjQueryС¼¼ÇÉ

      7¸öÓÐÓõÄjQueryС¼¼ÇÉ

      2016-02-26 13:02

    • jQueryÖÆ×÷selectË«ÏòÑ¡ÔñÁбí

      jQueryÖÆ×÷selectË«ÏòÑ¡ÔñÁбí

      2016-02-26 11:00

    • È«ÃæÏêϸµÄjQuery³£¼û¿ª·¢¼¼ÇÉÊÖ²á

      È«ÃæÏêϸµÄjQuery³£¼û¿ª·¢¼¼ÇÉÊÖ²á

      2016-02-26 10:02

    • Ç¿´óµÄjQueryÒƶ¯²å¼þTop 10

      Ç¿´óµÄjQueryÒƶ¯²å¼þTop 10

      2016-02-25 09:05

    ÍøÓѵãÆÀ
    Ì