jQuery中prevAll()方法用法實例
更新時間:2015年01月08日 09:35:20 投稿:shichen2014
這篇文章主要介紹了jQuery中prevAll()方法用法,實例分析了prevAll()方法的功能、定義及查找匹配元素集合之前所有同輩元素的使用技巧,需要的朋友可以參考下
本文實例講述了jQuery中prevAll()方法用法。分享給大家供大家參考。具體分析如下:
此方法查找匹配元素集合之前所有的同輩元素。
同輩元素集合可以通過選擇器進行篩選。
語法結(jié)構(gòu):
復(fù)制代碼 代碼如下:
$("selector").prevAll(expr)
參數(shù)列表:
實例代碼:
實例一:
復(fù)制代碼 代碼如下:
<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.dbjr.com.cn/" />
<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>
實例二:
復(fù)制代碼 代碼如下:
<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.dbjr.com.cn/" />
<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程序設(shè)計有所幫助。
相關(guān)文章
jQuery切換網(wǎng)頁皮膚并保存到Cookie示例代碼
這篇文章主要介紹通過jQuery切換網(wǎng)頁皮膚并將狀態(tài)保存到Cookie的相關(guān)代碼,需要的朋友可以參考下2014-06-06JQuery實現(xiàn)鼠標(biāo)移動到圖片上顯示邊框效果
鼠標(biāo)移動到圖片顯示邊框效果在瀏覽網(wǎng)頁的時候,大家也都見過,接下來使用jquery來實現(xiàn)這個功能,喜歡的朋友可以參考下2014-01-01jQuery基于隨機數(shù)解決中午吃什么去哪吃問題示例
這篇文章主要介紹了jQuery基于隨機數(shù)解決中午吃什么去哪吃問題,涉及jQuery基于事件響應(yīng)及隨機數(shù)動態(tài)操作頁面元素相關(guān)實現(xiàn)技巧,需要的朋友可以參考下2018-12-12深入理解jQuery中l(wèi)ive與bind方法的區(qū)別
本篇文章主要是對jQuery中l(wèi)ive與bind方法的區(qū)別進行了詳細的分析介紹,需要的朋友可以過來參考下,希望對大家有所幫助2013-12-12