jQuery内容过滤选择器

内容过滤选择器


:contains(内容)

包含内容选择器,获得节点内部必须通过标签包含指定的内容

$(“div:contains(beijing)”)

<div>linken love beijing</div>

<div>jack love shanghai</div>


:empty

获得空元素(内部没有任何元素/文本(空) )节点对象

$(“div:empty”)

<div>linken love beijing</div>

<div>jack love shanghai</div>

<div></div>

<div><img /></div>

<div>      </div>


 :has(选择器)

内部包含指定元素的选择器
$(“div:has(#apple)”)

<div>hello</div>

<div><p></p></div>

<div><span id=”apple”></span></div>

<div><span class=”apple”></span></div>


:parent

寻找的节点必须作为父元素节点存在

$(“div:parent”)

<div>linken love beijing</div>

<div>jack love shanghai</div>

<div></div>

<div><img /></div>

<div>      </div>

<!DOCTYPE html>
<html>
    <head>
        <title>php.cn</title>
        <meta charset="utf-8" />
        <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>

        <script>
        function f1(){
            //① $(":contains(text)")
            $("div:contains(beijing)").css('background-color','red');

            //② $(":empty")
            $("div:empty").css('width','200px');
            $("div:empty").css('height','100px');
            $("div:empty").css('background-color','pink');

            //③ $(":has(selector)")
            console.log($("div:has(.orange)"));

            //④ $(":parent")
            console.log($("div:parent"));
        }
        </script>
    </head>
    <body>
        <h1>内容过滤选择器</h1>
        <div>i love beijing</div>
        <div>jack love shanghai</div>
        <div></div>
        <div><img /></div>
        <div>      </div>
        <div><p class="orange"></p></div>
        <div><span class="orange"></span></div>

        <input type="button" value="触发" onclick="f1()" />
    </body>
</html>
Weiter lernen
||
<!DOCTYPE html> <html> <head> <title>php.cn</title> <meta charset="utf-8" /> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script> <script> function f1(){ //① $(":contains(text)") $("div:contains(beijing)").css('background-color','red'); //② $(":empty") $("div:empty").css('width','200px'); $("div:empty").css('height','100px'); $("div:empty").css('background-color','pink'); //③ $(":has(selector)") console.log($("div:has(.orange)")); //④ $(":parent") console.log($("div:parent")); } </script> </head> <body> <h1>内容过滤选择器</h1> <div>i love beijing</div> <div>jack love shanghai</div> <div></div> <div><img /></div> <div> </div> <div><p class="orange"></p></div> <div><span class="orange"></span></div> <input type="button" value="触发" onclick="f1()" /> </body> </html>
einreichenCode zurücksetzen