jQuery´úÂ뿪·¢¼¼ÇÉÊÕ¼¯,jquery³£ÓõĿª·¢´úÂë
½ñÌì·ÖÏíÒ»¸öjquery³£ÓõĿª·¢´úÂ룬´ó²¿·ÖÊÇÍøÓÑ×ܽáµÄ£¬×ܹ²60Ìõ¡£ºóÆÚÎÒÒ²»á½ÐøÍêÉÆ£¡ °ÑÎÒÔÚ¿ª·¢Öг£ÓõÄдÔÚÕâÀϣÍû³ÖÐø¹Ø×¢~~
1. ʹÓÃsiblings()À´´¦ÀíͬÀàÔªËØ
// Rather than doing this $('#nav li').click(function(){ $('#nav li').removeClass('active'); $(this).addClass('active'); }); // Do this instead $('#nav li').click(function(){ $(this).addClass('active').siblings().removeClass('active'); });2. Ñ¡Ôñ»òÕß²»Ñ¡Ò³ÃæÉÏÈ«²¿¸´Ñ¡¿ò
var tog = false; // or true if they are checked on load $('a').click(function() { $("input[type=checkbox]").attr("checked",!tog); tog = !tog; });3. »ùÓÚÊäÈëÎÄ×Ö¹ýÂËÒ³ÃæÔªËØ
//If the value of the element matches that of the entered text //it will be returned $('.gbin1Class').filter(function() { return $(this).attr('value') == $('input#gbin1Id').val() ; })4. È¡µÃÊó±êµÄXºÍY×ø±ê
$(document).mousemove(function(e){ $(document).ready(function() { $().mousemove(function(e){ $('#XY').html("Gbin1 X Axis : " + e.pageX + " | Gbin1 Y Axis " + e.pageY); }); });5. ʹµÃÕû¸öÁбíÔªËØ(LI)¿Éµã»÷
$("ul li").click(function(){ window.location=$(this).find("a").attr("href"); return false; }); <UL> <LI><A href="#">GBin1 Link 1</A></LI> <LI><A href="#">GBin1 Link 2</A></LI> <LI><A href="#">GBin1 Link 3</A></LI> <LI><A href="#">GBin1 Link 4</A></LI> </UL>6. ʹÓÃjQueryÀ´½âÎöXML
function parseXml(xml) { //find every Tutorial and print the author $(xml).find("Tutorial").each(function() { $("#output").append($(this).attr("author") + ""); }); }7. ÅжÏÒ»¸öͼƬÊÇ·ñ¼ÓÔØÍêÈ«
$('#theGBin1Image').attr('src', 'image.jpg').load(function() { alert('This Image Has Been Loaded'); });8. ʹÓÃjQueryÃüÃûʼþ
//Events can be namespaced like this $('input').bind('blur.validation', function(e){ // ... }); //The data method also accept namespaces $('input').data('validation.isValid', true);9. ÅжÏcookieÊÇ·ñ¼¤»î»òÕ߹رÕ
var dt = new Date(); dt.setSeconds(dt.getSeconds() + 60); document.cookie = "cookietest=1; expires=" + dt.toGMTString(); var cookiesEnabled = document.cookie.indexOf("cookietest=") != -1; if(!cookiesEnabled) { //cookies have not been enabled }10.Ç¿ÖƹýÆÚcookie
var date = new Date(); date.setTime(date.getTime() + (x * 60 * 1000)); $.cookie('example', 'foo', { expires: date });11. ʹÓÃÒ»¸ö¿Éµã»÷µÄÁ´½ÓÌæ»»Ò³ÃæÖÐËùÓÐURL
$.fn.replaceUrl = function() { var regexp = /((ftp|http|https)://(w+:{0,1}w*@)?(S+)(:[0-9]+)?(/|/([w#!:.?+=&%@!-/]))?)/gi; this.each(function() { $(this).html( $(this).html().replace(regexp,'<A href="$1">$1</A>') ); }); return $(this); } //usage $('#GBin1div').replaceUrl();12. ÔÚ±íµ¥ÖнûÓ᰻سµ¼ü¡±
´ó¼Ò¿ÉÄÜÔÚ±íµ¥µÄ²Ù×÷ÖÐÐèÒª·ÀÖ¹Óû§ÒâÍâµÄÌá½»±íµ¥£¬ÄÇôÏÂÃæÕâ¶Î´úÂë¿Ï¶¨·Ç³£ÓаïÖú£º
$("#form").keypress(function(e) { if (e.which == 13) { return false; } });13. Çå³ýËùÓÐµÄ±íµ¥Êý¾Ý
¿ÉÄÜÕë¶Ô²»Í¬µÄ±íµ¥ÐÎʽ£¬ÄãÐèÒªµ÷Óò»Í¬ÀàÐ͵ÄÇå³þ·½·¨£¬²»¹ýʹÓÃÏÂÃæÕâ¸öÏֳɷ½·¨£¬¾ø¶ÔÄÜÈÃÄãÊ¡²»ÉÙ¹¦·ò¡£
function clearForm(form) { // iterate over all of the inputs for the form // element that was passed in $(':input', form).each(function() { var type = this.type; var tag = this.tagName.toLowerCase(); // normalize case // it's ok to reset the value attr of text inputs, // password inputs, and textareas if (type == 'text' || type == 'password' || tag == 'textarea') this.value = ""; // checkboxes and radios need to have their checked state cleared // but should *not* have their 'value' changed else if (type == 'checkbox' || type == 'radio') this.checked = false; // select elements need to have their 'selectedIndex' property set to -1 // (this works for both single and multiple select elements) else if (tag == 'select') this.selectedIndex = -1; }); };14. ½«±íµ¥Öеİ´Å¥½ûÓÃ
ÏÂÃæµÄ´úÂë¶ÔÓÚajax²Ù×÷·Ç³£ÓÐÓã¬Äã¿ÉÒÔÓÐЧµÄ±ÜÃâÓû§¶à´ÎÌá½»Êý¾Ý£¬¸öÈËÒ²¾³£Ê¹Óãº
½ûÓð´Å¥£º
$("#somebutton").attr("disabled", true);Æô¶¯°´Å¥£º
$("#submit-button").removeAttr("disabled");¿ÉÄÜ´ó¼ÒÍùÍù»áʹÓÃ.attr(¡®disabled¡¯,false);£¬²»¹ýÕâÊDz»ÕýÈ·µÄµ÷Óá£
15. ÊäÈëÄÚÈݺóÆôÓõݽ»°´Å¥
Õâ¸ö´úÂëºÍÉÏÃæÀàËÆ£¬¶¼ÊôÓÚ°ïÖúÓû§¿ØÖÆ±íµ¥µÝ½»°´Å¥¡£Ê¹ÓÃÕâ¶Î´úÂëºó£¬µÝ½»°´Å¥Ö»ÓÐÔÚÓû§ÊäÈëÖ¸¶¨ÄÚÈݺó²Å¿ÉÒÔÆô¶¯¡£
$('#username').keyup(function() { $('#submit').attr('disabled', !$('#username').val()); });16.½ûÖ¹¶à´ÎµÝ½»±íµ¥
¶à´ÎµÝ½»±íµ¥¶ÔÓÚwebÓ¦ÓÃÀ´ËµÊǸö±È½ÏÍ·ÌÛµÄÎÊÌ⣬ÏÂÃæµÄ´úÂëÄܹ»ºÜºÃµÄ°ïÖúÄã½â¾öÕâ¸öÎÊÌ⣺
$(document).ready(function() { $('form').submit(function() { if(typeof jQuery.data(this, "disabledOnSubmit") == 'undefined') { jQuery.data(this, "disabledOnSubmit", { submited: true }); $('input[type=submit], input[type=button]', this).each(function() { $(this).attr("disabled", "disabled"); }); return true; } else { return false; } }); });17. ¸ßÁÁÏÔʾĿǰ¾Û½¹µÄÊäÈë¿ò±êʾ
¡¡