亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

jQuery ??? ?? ???

jQuery ??? ??? ???? ??? ??? ?? DOM ??? ??? ?? ?? ?? ?? ??? ???? ?????.

<div>John Resign</div>
<div>George Martin</div>
<div>Malcom John Sinclair</div>
<div>J.Ohn</div>
<div></div>
<p></p>
<div><p>Has p</p></div>

1. ??? ??? ??? ——:contains(text)

???:

E:contains(text)  //E是指DOM元素,:contains(text)包含的文本,text是指定查找的字符串

??:

??? ??? "text"? ???? ?? ??

?? ?:

??? ??

Instance :

<script type="text/javascript">   $(document).ready(function(){
      $('div:contains(John)').css('background','#f36');
   });</script>

??:

??? "John"? ??? div ??? ??? ??

??:

?? HTML ??? ???? ? ?? div? ??? ? ? ????. it ???? "John"??? ???? ???? ????. ???? ?? "John"??? ???? ??? div? ???? ???? ??? ? ??? ? ?? div? ???? "#f36"? ?? ??? ? ? ????. , ?? ??? ? ? ???? ?? Firefox? Firebug ??? ?? HTML? ?? ??? ? ? ????.

2. ??? ??? ??? - :empty

??? :

E:empty //其中E為DOM元素,:empty是指DOM元素中不包含任何子元素或文本

??:

?? ??? ???? ?? ? ??? ?????

?? ?:

Collection elements

Instance:

<script type="text/javascript">   $(document).ready(function(){
      $('div:empty').css('background','#f36');
   });</script>

Function:

?? ?? ?? ??? ??? div? ???( ???? ?? ?? ??), ? ???? ???? ?? div? ??? ??

??:

?? HTML? ?? ???? ?? ??? ??? ?? ???? ??? ??? ???? ?? . ?? ??? ??? ???? ?? ??? div ? p ??? ????. ?? ? ???? ?? ??? ??? ???? ???? ?? div? ???? ?????? ???? div?? "#f36"? ???? ?????. . HTML ?? ??:

3. ??? ??? ??? - :has(selector)

Selector:

E:has(selector)  //其中E為有效果DOM元素標(biāo)簽,:has(selector)含有一個選擇器,selector用于篩選的選擇器

Description:

??? ??? ???? ??? ???? ?? ??

?? ?:

??? ??

????:

<script type="text/javascript">   $(document).ready(function(){
      $('div:has(p)').css('background','#f36');
   });</script>

??:

?? ??? ??? div ??? ??? ?? P

??:

? ??? ??? ????. div ?? ?? P? ????? ? ?? ??? ???? div ??? ???? ???? "#f36"?? ?????. ??? HTML:

4. ??? ??? ??? - :parent

???:

E:parent  //E為有效的DOM元素標(biāo)簽,:parent含有子元素或文本內(nèi)容

??:

?? ?? ?? ???? ??? ?? ?? ??

?? ?:

??? ??

????:

<script type="text/javascript">   $(document).ready(function(){
      $('div:parent').css('background','#f36');
   });</script>

??:

?? ?? ??? ??? ???? ??? div? ??????. ?, div? ?? ??? ???? ???? ??? ???? ?????.

??:

? ???? ?? ??? ??? ???? ???? ?? div? p ??? ??? ????. ??? div? ????? ??? ?????. , ? ? ??? ???? ?? ??? ?? ???? ??? div? ???? "#f36"?? ???????. HTML?

???? ??
||
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <title></title> <script src="http://code.jquery.com/jquery-3.1.1.min.js"></script> <style> .left { width: auto; height: 120px; } .left div { width: 70px; height: 70px; padding: 5px; margin: 5px; float: left; background: #bbffaa; border: 1px solid #ccc; } .bottom { width: 800px; } .bottom div, .bottom span { display: block; width: 80px; height: 80px; margin: 5px; background: #bbffaa; float: left; font-size: 14px; } .bottom .small { width: 60px; height: 25px; font-size: 12px; background: #fab; } </style> </head> <body> <h2>內(nèi)容篩選器</h2> <h3>:contains/:has</h3> <div class="left"> <div class="div"> <p>:contains</p> </div> <div class="div"> <p>:contains</p> </div> <div class="div"> <p> <span>:has</span> </p> </div> <div class="div"> <p>:contains</p> </div> </div> <script type="text/javascript"> //查找所有class='div'中DOM元素中包含"contains"的元素節(jié)點 //并且設(shè)置顏色 $(".div:contains(':contains')").css("color", "#CD00CD"); </script> <script type="text/javascript"> //查找所有class='div'中DOM元素中包含"span"的元素節(jié)點 //并且設(shè)置顏色 $(".div:has(span)").css("color", "blue"); </script> <h3>:parent/:empty</h3> <div class="left"> <div class="aaron"> <a>:parent</a> </div> <div class="aaron"> <a>:parent</a> </div> <div class="aaron"> <a>:parent</a> </div> <div class="aaron"> <a></a> </div> </div> <script type="text/javascript"> //選擇所有a元素,找到對應(yīng)的父元素 //增加一個藍(lán)色的邊框 $("a:parent").css("border", "3px groove blue"); </script> <script type="text/javascript"> //找到a元素下面的所有空節(jié)點(沒有子元素) //增加一段文本與邊框 $("a:empty").text(":empty").css("border", "3px groove red"); </script> </body> </html>