jquery常用技術

4526 ワード

1.      
    (1)   :   
    $("input[id^='code']");//id   code     input     
    $("input[id$='code']");//id   code     input     
    $("input[id*='code']");//id    code   input     
    (2)         
    $("tbody tr:even"); //          tr     
    $("tbody tr:odd");  //          tr     
    (3)  jqueryObj      input     
    jqueryObj.children("input").length;   
    (4)  class main          <a>     
    $(".main > a");    
    (5)         
    jqueryObj.next("div");//  jqueryObj          div,nextAll       
    (6)         
    $("div").eq(0);//     div     
2.      
    (1)not   
    $("#code input:not([id^='code'])");//id code      id code     input     
3.     
    (1)          
    var inputObj = $("<input type='text'/>");   
    (2)          
    jqueryObj.html();//html   
    jqueryObj.text();//      
    (3)          
    jqueryObj.val();//    value    
    jqueryObj.attr("    :name");//          
    (4) dom         
    inputObj.appendTo(jqueryObj); //          jqueryObj    
    inputObj.trigger("focus").trigger("select");//           
    (5)  CSS  
    inputObj.css({zIndex:3}); //     
    inputObj.css("zIndex");
    (6)     
    var timeoutId = setTimeout(function(){  },300);//  300  ,        
    clearTimeout(timeoutId);//    ,              
    (7)      
    var timerId = setInterval(function(){  },300);//   300  ,       
    clearInterval(timerId);//    ,            
    (8)  
    inputObj.animate{"top":3,"left":3},300,function(){ });
4.     
    //              
    jqueryObj.keyup(function(event){   
        var keyCode = event.which;//           ,    13   
    }   
    mouseover(fn),mouseout(fn)//    ,      
5.     
    show(),toggle(),slideDown(),slideUp(),slideToggle(),fadeIn(),fadeOut(),fadeTo()  
6.       
    $('#someField').val($.trim($('#someField').val()));//    ,  :$.trim(value)   
7.         
    (function($){   
        $.extend({   
            //          
            controlAllCheckBox:function(tableId,isSelectAll){   
                if(tableId==undefined){   
                    throw new Error("tableId     ");               
                }   
                else{   
                    if(isSelectAll==undefined){   
                        throw new Error("isSelectAll     ");               
                    }   
                    else{   
                        if(isSelectAll==true){   
                            $("#"+tableId+" :checkbox").each(function(){   
                                $(this).attr('checked','true');   
                            })   
                        }   
                        else{   
                            $("#"+tableId+" :checkbox").each(function(){   
                                $(this).attr('checked','');   
                            })   
                        }   
                    }   
                }   
            },   
            //     checkbox  id   
            getCheckedIds:function(tableId){   
                var checkboxs = $("#"+tableId+" :checkbox:checked");   
                if(checkboxs.size()==0){   
                    throw new Error("      ");             
                }   
                else {   
                    var ids = "";   
                    checkboxs.each(function(){   
                        if(ids==''){   
                            ids+=$(this).attr('id');   
                        }   
                        else{   
                            ids+=","+$(this).attr('id');   
                        }   
                    })   
                    return ids;   
                }   
            }   
        })   
    })(jQuery);