jQuery ???
jQuery? ?? ?? ??? CSS ??? ???? ???? ??? ?? ?? DOM ??? ?? ??, ?? ??, ?? ?? ??? ???? ??? ? ?? ??? ?????.
??? ???? jQuery ???? ???? ???? CSS ???? ?? ?? CSS ???? ?????
CSS ???? ????? ??? ?? ??? ???? ??? ???? ???? ? ?????
jQuery ???? ??????? ??? ?? ? ????? . ??? ?? ? ??? ??? ???? ??? ??, ?? ?? ??? ?? ????
jQuery ???? ??? ? "$()" ??? ???? CSS ??? jQuery ??? ????? ??? ? ???? ?? ??? ??? jQuery ??? ?????. ?? ?? ?? DOM ???? ?? ??? ??? ? ????.
Element Selector
jQuery ?? ???? ??? ???? ??? ?????.
???? ?? <p> ?? ??:
$("p")
?
???? ??? ???? ?? <p> ??? ?????.
Run ????? ??? ???#id selector
jQuery #id selector? HTML ??? id ??? ?? ??? ??? ?????. ??: ID? ???? ? ?? ??? ? ????. ????? ???? ? ??? ???? ???? ???. ??? ???? ? ? ???? CSS ???? ???? ? ? ?? ??? ??? ??? ?????. ??? jQuery?? ??? ?? ??? ????? ??? ID? ???? ???. ????? ??? ID? ???? ??ID?? ??? ???? ??? ??? ????.$("#test")
Example
???? ??? ???? is id="test "??? ?? ??? ????? ????:<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"> </script> <script> $(document).ready(function(){ $("button").click(function(){ $("p").css('color','red'); //添加一個行為 }); }); </script> </head> <body> <h2>這是一個標題</h2> <p>這是一個段落。</p> <p>這是另一個段落。</p> <button>點我</button> </body> </html>????? ???? ??? ???
.class selector
jQuery ??? ???? ??? ????? ??? ?? ? ????.
??? ??? ????:
$(".test")
Instance
???? ??? ???? class="test" ??? ?? ?? ??? ??? ?????.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("button").click(function(){ $("#test").css('color','red'); }); }); </script> </head> <body> <h2>標題</h2> <p>段落</p> <p id="test">我變顏色了</p> <button>點我</button> </body> </html>
???? ??? ??
? ?? ??? ??
Syntax | Description |
---|---|
$(this) | ?? HTML ?? |
$("p") | ?? <p> ?? |
$("p.intro") | class="intro"? ?? <p> ?? |
$(".intro") | ?? ???= " ??" ?? |
$("#intro") | id="intro" ?? |
$("ul li:first") | ? <ul> ??? ? ??< |
$("[href$='.jpg']") | ?? ?? ".jpg"? ??? ?? href ?? |
$("div#intro . head") | id="intro" <div> ??? class="head"? ?? ?? ?? |