jQuery中parentsUntil()方法用法实例(2)

参数列表:
参数   描述  
element   可选。用于筛选祖先元素的DOM元素或者jQuery元素。  
filter   可选。用于对取得的祖先元素集合进行筛选。  

实例:

实例一:

复制代码 代码如下:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta content="https://www.jb51.net/" />
<title>脚本之家</title>
<script type="text/javascript" src="https://www.jb51.net/mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        $("li").parentsUntil(document.getElementById("inner")).css("border","1px solid blue");
    })
</script>
</head>
<body>
    <div>
        <div>脚本之家欢迎您</div>
        <div>
            <ul>
                <li>HTML专区</li>
                <li>Javascript专区</li>
                <li>Div+CSS专区</li>
                <li>Jquery专区</li>
            </ul>
            <ul>
                <li>HTML专区</li>
                <li>Javascript专区</li>
                <li>Div+CSS专区</li>
                <li>Jquery专区</li>
            </ul>
        </div>
    </div>
</body>
</html>

实例二:

复制代码 代码如下:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta content="https://www.jb51.net/" />
<title>脚本之家</title>
<script type="text/javascript" src="https://www.jb51.net/mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        $("li").parentsUntil(document.getElementById("inner"),".second").css("border","1px solid blue");
    })
</script>
</head>
<body>
    <div>
        <div>脚本之家欢迎您</div>
        <div>
            <ul>
                <li>HTML专区</li>
                <li>Javascript专区</li>
                <li>Div+CSS专区</li>
                <li>Jquery专区</li>
            </ul>
            <ul>
                <li>HTML专区</li>
                <li>Javascript专区</li>
                <li>Div+CSS专区</li>
                <li>Jquery专区</li>
            </ul>
        </div>
    </div>
</body>
</html>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wgxgdj.html