jQuery選取器之基本選取器

來源:互聯網
上載者:User

標籤:ext   org   public   div   www   onclick   key   cli   set   

獲得頁面各種元素節點

1.$(#id屬性值)

$(‘#useremail‘).css(‘color‘,‘red‘);

2. $(tag標籤名稱)

$(‘h2‘).css(‘backgroundColor‘,‘pink‘);$(‘input‘).css(‘backgroundColor‘,‘lightblue‘);

3.$(.class屬性值)

$(‘.pear‘).css(‘fontSize‘,‘30px‘);

4.$(*) 萬用字元(獲得頁面"全部"元素節點對象)
         

$(‘*‘).css(‘backgroundColor‘,‘gray‘);

5.$(s1,s2,s3) 聯合選取器,節點滿足s1/s2/s3之一條件即可 (s的意思selector)
          

$(‘h2,#userqq‘).css(‘color‘,‘green‘);

下面是完整例子:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html>    <head>        <title>建立網頁</title>        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />        <meta name="description" content="" />        <meta name="keywords" content="" />        <script type="text/javascript" src="./jquery-1.4.4.js"></script>        <script type="text/javascript">        function f1(){            //獲得頁面各種元素節點            //① $(#id屬性值)            $(‘#useremail‘).css(‘color‘,‘red‘);            //② $(tag標籤名稱)            $(‘h2‘).css(‘backgroundColor‘,‘pink‘);            $(‘input‘).css(‘backgroundColor‘,‘lightblue‘);            //③ $(.class屬性值)            $(‘.pear‘).css(‘fontSize‘,‘30px‘);            //④ $(*) 萬用字元(獲得頁面"全部"元素節點對象)            //$(‘*‘).css(‘backgroundColor‘,‘gray‘);            //⑤ $(s1,s2,s3) 聯合選取器,節點滿足s1/s2/s3之一條件即可            //    (s的意思selector)            $(‘h2,#userqq‘).css(‘color‘,‘green‘);        }        </script>        <style type="text/css">        /*        #username{}        #useremail{}        .pear{}        input{}        *{樣式初始化}        #username,.apple,input{}        */        </style>    </head>    <body>        <h2>jquery基本選取器(思想來之css樣式選取器)</h2>        <p><input type="text" id="username" value="linken" /></p>        <p><input type="text" id="useremail" class="apple" value="[email protected]" /></p>        <p><input type="text" id="userqq" class="pear" value="28323782943" /></p>        <p><input type="button" value="觸發" onclick="f1()" /></p>    </body></html>

 

jQuery選取器之基本選取器

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.