jQuery prev ~ siblings選擇器使用介紹
更新時間:2013年08月09日 11:33:45 作者:
正如標(biāo)題所言其所用為匹配 prev 元素之后的所有 siblings 元素,下面為大家分享個示例,不了解的朋友可以學(xué)習(xí)下
1、prev ~ siblings:匹配 prev 元素之后的所有 siblings 元素
2、
(1)prev:任何有效選擇器
(2)siblings:一個選擇器,并且它作為第一個選擇器的同輩
3、示例
(1)源碼
siblings.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=gb2312" />
<title>prev ~ siblings選擇器</title>
<script type="text/javascript" src="jquery-2.0.3.js"></script>
<style type="text/css">
body{
width:100%;
height:100%;
font-size:18px;
color:#00FF00;
}
</style>
<script type="text/javascript">
$(function(){
//匹配所有元素
$("*").css("background-color","#FFE4E1");
//prev ~ siblings選擇器運用
$("label ~ input").css("font-size","30px");
//點擊事件,prev ~ siblings選擇器運用
$("#pwd").click(function(){
alert("我被選中!");
});
});
</script>
</head>
<body>
<form id="form_body">
<label class="username">用戶名:</label>
<input type="text" id="username" name="username"/>
<label class="password">密 碼:</label>
<input type="password" id="password" name="password"/>
<input type="button" id="login" name="login" value="登錄"/>
<input type="reset" id="reset" name="reset" value="重置"/>
<input type="checkbox" id="pwd" name="pwd"/>記住密碼
</form>
</body>
</html>
(2)顯示結(jié)果如下
2、
(1)prev:任何有效選擇器
(2)siblings:一個選擇器,并且它作為第一個選擇器的同輩
3、示例
(1)源碼
siblings.html
復(fù)制代碼 代碼如下:
<!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=gb2312" />
<title>prev ~ siblings選擇器</title>
<script type="text/javascript" src="jquery-2.0.3.js"></script>
<style type="text/css">
body{
width:100%;
height:100%;
font-size:18px;
color:#00FF00;
}
</style>
<script type="text/javascript">
$(function(){
//匹配所有元素
$("*").css("background-color","#FFE4E1");
//prev ~ siblings選擇器運用
$("label ~ input").css("font-size","30px");
//點擊事件,prev ~ siblings選擇器運用
$("#pwd").click(function(){
alert("我被選中!");
});
});
</script>
</head>
<body>
<form id="form_body">
<label class="username">用戶名:</label>
<input type="text" id="username" name="username"/>
<label class="password">密 碼:</label>
<input type="password" id="password" name="password"/>
<input type="button" id="login" name="login" value="登錄"/>
<input type="reset" id="reset" name="reset" value="重置"/>
<input type="checkbox" id="pwd" name="pwd"/>記住密碼
</form>
</body>
</html>
(2)顯示結(jié)果如下
相關(guān)文章
JQuery 插件模板 制作jquery插件的朋友可以參考下
JQuery 插件模板 制作jquery插件的朋友可以參考下2010-03-03
jQuery+CSS實現(xiàn)的table表格行列轉(zhuǎn)置功能示例
這篇文章主要介紹了jQuery+CSS實現(xiàn)的table表格行列轉(zhuǎn)置功能,涉及jQuery事件響應(yīng)及頁面元素屬性動態(tài)操作相關(guān)實現(xiàn)技巧,需要的朋友可以參考下2018-01-01
三分鐘帶你玩轉(zhuǎn)jQuery.noConflict()
這篇文章主要介紹了三分鐘帶你玩轉(zhuǎn)jQuery.noConflict() 的相關(guān)資料,需要的朋友可以參考下2016-02-02
基于jQuery的公告無限循環(huán)滾動實現(xiàn)代碼
今天看到一個網(wǎng)站的公告欄一個小效果,如果有2條公告或以上就有個滾動效果,特整理下分享給大家2012-05-05

