jquery选择器空格与大于号、加号与波浪号的区别(转)
空格:$('parent childchild')表示获取parent下的所有的childchild节点,所有的子孙。
大于号:$('parent child')表示获取parent下的所有child的儿子,第一代。
加号:$('pre + nextbrother')表示获得pre节点的下一个兄弟节点,相当于next()方法
波浪号:$('pre ~ brother')表示获取pre节点的后面的所有兄弟节点,相当于nextAll()方法。
下面是一个小例子,看看他们的区别吧~~~~
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title> New Document </title> <meta name="Generator" content="EditPlus"> <meta name="Author" content=""> <meta name="Keywords" content=""> <meta name="Description" content=""> <script src='f:/study/jquery.js'></script> <script> $(function(){ $("#b").append($("#a span").clone()); $("#c").append($("#span12 + span").clone()); $("#d").append($("#span12 ~ span").clone()); $("#e").append($("#a > span").clone()); }) </script> </head> <body> <div id='a'> <span>span1</span> <div> <span>span1.1</span> <span id='span12'>span1.2</span> <span>span1.3</span> <span>span1.4</span> <span>span1.5</span> <span>span1.6</span> </div> <span>span2</span> <div> <span>span2.1</span> <span>span2.2</span> <span>span2.3</span> <span>span2.4</span> <span>span2.5</span> <span>span2.6</span> </div> <span>span3</span> <span>span4</span> </div> <hr> <div id='b'></div> 空格: <hr> <div id='c'></div> +: <hr> <div id='d'></div> ~: <hr> <div id='e'> > </div> </body> </html>
相关推荐
83510998 2020-08-08
tthappyer 2020-07-25
tztzyzyz 2020-07-05
87281248 2020-07-04
82244951 2020-06-28
89510194 2020-06-27
牵手白首 2020-06-14
开心就好 2020-06-10
89510194 2020-06-06
Web全栈笔记 2020-06-04
tztzyzyz 2020-05-31
开心就好 2020-05-27
牵手白首 2020-05-19
牵手白首 2020-05-16
donghongbz 2020-05-15
tztzyzyz 2020-05-15
hehekai 2020-05-08