jQuery中prevAll()方法用法实例
更新时间:2015年01月08日 09:35:20 投稿:shichen2014
这篇文章主要介绍了jQuery中prevAll()方法用法,实例分析了prevAll()方法的功能、定义及查找匹配元素集合之前所有同辈元素的使用技巧,需要的朋友可以参考下
本文实例讲述了jQuery中prevAll()方法用法。分享给大家供大家参考。具体分析如下:
此方法查找匹配元素集合之前所有的同辈元素。
同辈元素集合可以通过选择器进行筛选。
语法结构:
复制代码 代码如下:
$("selector").prevAll(expr)
参数列表:
实例代码:
实例一:
复制代码 代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="https://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 div").prevAll().css("color","blue")
})
</script>
</head>
<body>
<div class="father">
<p>我是p元素</p>
<span>我是span元素</span>
<p>我是p元素</p>
<div>我是div元素</div>
</div>
</body>
</html>
实例二:
复制代码 代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="https://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 div").prevAll("span").css("color","blue")
})
</script>
</head>
<body>
<div class="father">
<p>我是p元素</p>
<span>我是span元素</span>
<p>我是p元素</p>
<div>我是div元素</div>
</div>
</body>
</html>
希望本文所述对大家的jQuery程序设计有所帮助。
相关文章
jquery+ajax+C#实现无刷新操作数据库数据的简单实例
本篇文章主要是对jquery+ajax+C#实现无刷新操作数据库数据的简单实例进行了介绍,需要的朋友可以过来参考下,希望对大家有所帮助2014-02-02jquery.combobox中文api和例子,修复了上面的小bug
关于jquery.combobox,这个jquery的插件从官网上直接下载下来使用还有bug,以下是我对其api做的简单翻译,而且修复了上面的bug。2011-03-03
最新评论