JQuery基本選取器

來源:互聯網
上載者:User

JQuery基本選取器
選取器

描述

返回

#id

根據給定的id匹配一個元素

單個元素

.class

根據給定的類名匹配元素

集合元素

element

根據給定的元素名匹配元素

集合元素

*

匹配所有元素

集合元素

Selector1,selector2,...

將每一個選取器匹配到的元素合并後一起返回

集合元素

 例子:

[javascript] 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
        <title>New Web Project</title> 
        <script type="text/javascript" src="jquery-core/jquery-1.8.0.js"></script> 
        <script type="text/javascript"> 
            $(function(){ 
                $('#bt1').click(function(){ 
                    alert('id選取器:'+$('#d1').html() 
                    +"\nclass選取器:"+$('.c1').html() 
                    +"\n元素選取器:"+$('p').eq(0).html() 
                    +"\n*選取器:"+$('*').eq(5).html() 
                    +"\n多選取器選中的個數:"+$('div,p,#bt1').length 
                    ); 
                }); 
            }); 
             
             
             
        </script> 
    </head> 
    <body> 
        <div id="d1">我是一個div</div> 
        <div class="c1">我是一個div2</div> 
        <p>我是一個p</p> 
        <input type="button" value="button" id="bt1" /> 
         
    </body> 
</html> 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.