您好,欢迎来到纷纭教育。
搜索
您的当前位置:首页jQuery中prevAll()方法用法实例

jQuery中prevAll()方法用法实例

来源:纷纭教育


这篇文章主要介绍了jQuery中prevAll()方法用法,实例分析了prevAll()方法的功能、定义及查找匹配元素集合之前所有同辈元素的使用技巧,需要的朋友可以参考下

本文实例讲述了jQuery中prevAll()方法用法。分享给大家供大家参考。具体分析如下:

此方法查找匹配元素集合之前所有的同辈元素。
同辈元素集合可以通过选择器进行筛选。

语法结构:

代码如下:

$("selector").prevAll(expr)

参数列表:

参数描述
expr可选。用于过滤的表达式。

实例代码:

实例一:

代码如下:

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.gxlcms.com/" />
<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").prevAll().css("color","blue") 
}) 
</script>
</head>
<body>
<p class="father">
 <p>我是p元素</p>
 <span>我是span元素</span>
 <p>我是p元素</p>
 <p>我是p元素</p>
</p>
</body>
</html>

实例二:

代码如下:

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.gxlcms.com/" />
<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").prevAll("span").css("color","blue") 
}) 
</script>
</head>
<body>
<p class="father">
 <p>我是p元素</p>
 <span>我是span元素</span>
 <p>我是p元素</p>
 <p>我是p元素</p>
</p>
</body>
</html>

Copyright © 2019- fenyunshixun.cn 版权所有 湘ICP备2023022495号-9

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务