jQuery共通フィルタセレクタ

6752 ワード

                              DOM   ,      CSS            ,           (:)  。         ,                ,    、     、    、                 
1.         

    
    
    
    
 
:first 
         
      
 $(“div:first”)      <div>        <div>    
 
:last 
          
      
 $(“div:last”)      <div>         <div>    
 
:not(selector) 
                 
      
 $(“input:not(.myClass)”)    class    myClass   <input>    
 
:even 
             ,    0    
      
 $(“input:even”)          <input>    
 
:odd 
             ,    0    
      
 $(“input:odd”)          <input>    
 
:eq(index) 
        index    ( index   0   ) 
      
 $(“input:eq(1)”)        1   <input>    
 
:gt(index) 
        index    ( index   0   ) 
      
 $(“input:gt(1)”)        1   <input>   ( :   1 ,     1 ) 
 
:lt(index) 
        index    ( index   0   ) 
      
 $(“input:lt(1)”)        1   <input>   ( :   1 ,     1 ) 
 
:header 
          ,   h1,h2,h3    
      
 $(“:header”)          <h1> , <h2> , <h3> …… 
 
:animated 
                 
      
 $(“div:animated”)             <div>    
 

  

2 .        

    
    
    
    
 
:contains(text) 
          “ text ”    
      
 $(“div:contains(‘   ”)”)       “ ”  <div>    
 
:empty 
                  
      
 $(“div:empty”)         (      )  <div>    
 
:has(selector) 
                  
      
 $(“div:has(p)”)      <p>     <div> 
 
:parent 
                
      
 $(“div:parent”)        (      )  <div> 
 

  

3 .         

    
    
    
    
 
  

  

  

:hidden 
   

  

  

           
   

  

  

     
 $(“:hidden”)           ,   <input type=”hidden”/> , <div style=”display:none;”>   <div     style=”visibility:hidden;”>    ,       <input>   ,     $(“input:hidden”) 
 
:visible 
          
      
 $(“div:visible”)         <div> 
 

  

4 .        

    
    
    
    
 
[attribute] 
            
      
 $(“div[id]”)        id     
 
[attribute=value] 
         value     
      
 $(“div[title=test]”)      title  “ test ”  <div>    
 
[attribute!=value] 
           value     
      
 $(“div[title!=test]”)      title    “ test ”  <div>   ( :     title   <div>        ) 
 
[attribute^=value] 
         value       
      
 $(“div[title^=test]”)      title  “ test ”    <div>    
 
[attribute$=value] 
         value       
      
 $(“div[title$=test]”)      title  “ test ”    <div>    
 
[attribute*=value] 
          value     
      
 $(“div[title$=test]”)      title   “ test ”  <div>    
 
[selector1][selector2][selector] 
                    ,      。     ,       
      
 $(“div[id][title$=’test’]”)        id ,     title  “ test ”    <div>    
 

  

5 .         

    
    
    
    
 
:nth-child 

(index/even/odd/equation) 
            index        ( odd ) ( even )  ,( index   1   ) 
      
 :eq(index)        ,  :nth-child              ,   :nth-child(index)   index    1    ,  :eq(index)    0     
 
:first-child 
                
      
 :first        ,  :first-child                。 

  : $(“ul li:first-child”)      <ul>      <li>    
 
:last-child 
               
      
 :last        ,  :last-child                 。 

  : $(“ul li:last-child”)      <ul>       <li>    
 
:only-child 
                  ,       ,            ,       
      
 $(“ul li:only-child”)   <ul>            <li>    
 

  

  

  

6 .            

    
    
    
    
 
:enabled 
          
      
 $(“#form1 :enabled”)    id  “ form1”            
 
:disabled 
           
      
 $(“#form1 :disabled”)    id  “ form1”             
 
:checked 
           (   ,   ) 
      
 $(“input :checked”)          <input>    
 
:selected 
             (    ) 
      
 $(“select :selected”)              
 

  

        <input>     ,    : 

$(“form1 input:enabled”).val(“         ”); 

          ,    : 

$(“input : checked ”).length; 

          ,    : 

$(“select:selected”).text(); 

  ,                 

  

  

7 .            

    
    
    
    
 
:input 
       <input>,<textarea>, 

<select>,<button>    
      
 $(“:input)       <input>,<textarea>,<select>, 

<button>    
 
:text 
            
      
 $(“:text”)            
 
:password 
          
      
 $(“:password”)          
 
:radio 
          
      
 $(“:radio”)          
 
:checkbox 
          
      
 $(“:checkbox”)          
 
:submit 
           
      
 $(“:submit”)           
 
:image 
           
      
 $(“:image”)           
 
:reset 
           
      
 $(“:reset”)           
 
:button 
         
      
 $(“:button”)         
 
:file 
          
      
 $(“:file”)          
 
:hidden 
            
      
 $(“:hidden”)            
 

  

            ,    : 

$(“form1 :input”).length; 

            ,    : 

$(“form1 :text”).length; 

           ,    : 

$(“form1 :password”).length; 

  ,