这篇文章主要介绍了jquery中prevuntil()方法用法,实例分析了按条件查找匹配元素之前所有的同辈元素的使用技巧,需要的朋友可以参考下
本文实例讲述了jQuery中prevUntil()方法用法。分享给大家供大家参考。具体分析如下:
此函数查找匹配元素之前所有的同辈元素,直到遇到expr表达式、DOM元素或者jQuery元素匹配的那个元素为止。
可以使用可选的表达式对同辈元素集合进行筛选。
注意:祖先元素中并不包含expr表达式、DOM元素或者jQuery元素匹配的元素。
语法:
语法 一:
代码如下:
$(selector).prevUntil(expr,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 name="author" content="http://www.jb51.net/" />
<title>本站</title>
<style type="text/css">
.father {
height:200px;
width:200px;
border:1px solid blue;
}
</style>
<script type="text/
javascript
" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(
document
).ready(function(){
$(".father p").prevUntil(".firstp").css("color","blue")
})
</script>
</head>
<body>
<p class="father">
<p class="firstp">我是p元素</p>
<span>我是span元素</span>
<p>我是p元素</p><div class="aritcle_card flexRow">
<div class="artcardd flexRow">
<a class="aritcle_card_img" href="/xiazai/code/8874" title="eMart 网店系统"><img
src="https://img.php.cn/upload/webcode/000/000/007/175705920583388.jpg" alt="eMart 网店系统" onerror="this.onerror='';this.src='/static/lhimages/moren/morentu.png'" ></a>
<div class="aritcle_card_info flexColumn">
<a href="/xiazai/code/8874" title="eMart 网店系统">eMart 网店系统</a>
<p>功能列表:底层程序与前台页面分离的效果,对页面的修改无需改动任何程序代码。完善的标签系统,支持自定义标签,公用标签,快捷标签,动态标签,静态标签等等,支持标签内的vbs语法,原则上运用这些标签可以制作出任何想要的页面效果。兼容原来的栏目系统,可以很方便的插入一个栏目或者一个栏目组到页面的任何位置。底层模版解析程序具有非常高的效率,稳定性和容错性,即使模版中有错误的标签也不会影响页面的显示。所有的标</p>
</div>
<a href="/xiazai/code/8874" title="eMart 网店系统" class="aritcle_card_btn flexRow flexcenter"><b></b><span>下载</span> </a>
</div>
</div>
<p>我是p元素</p>
</p>
</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 name="author" content="http://www.jb51.net/" />
<title>本站</title>
<style type="text/css">
.father {
height:200px;
width:200px;
border:1px solid blue;
}
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".father p").prevUntil(".firstp","span").css("color","blue")
})
</script>
</head>
<body>
<p class="father">
<p class="firstp">我是p元素</p>
<span>我是span元素</span>
<p>我是p元素</p>
<p>我是p元素</p>
</p>
</body>
</html>语法二:
代码如下:
$(selector).prevUntil(element,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 name="author" content="http://www.jb51.net/" />
<title>本站</title>
<style type="text/css">
.father {
height:200px;
width:200px;
border:1px solid blue;
}
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".father p").prevUntil(document.getElementById("firstp")).css("color","blue")
})
</script>
</head>
<body>
<p class="father">
<p id="firstp">我是p元素</p>
<span>我是span元素</span>
<p>我是p元素</p>
<p>我是p元素</p>
</p>
</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 name="author" content="http://www.jb51.net/" />
<title>本站</title>
<style type="text/css">
.father {
height:200px;
width:200px;
border:1px solid blue;
}
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".father p").prevUntil(document.getElementById("firstp"),"span").css("color","blue")
})
</script>
</head>
<body>
<p class="father">
<p id="firstp">我是p元素</p>
<span>我是span元素</span>
<p>我是p元素</p>
<p>我是p元素</p>
</p>
</body>
</html>









