jQuery prev ~ siblings選擇器使用介紹
更新時間:2013年08月09日 11:33:45 作者:
正如標題所言其所用為匹配 prev 元素之后的所有 siblings 元素,下面為大家分享個示例,不了解的朋友可以學習下
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)文章
JQERY limittext 插件0.2版(長內(nèi)容限制顯示)
JQERY limittext 插件為長內(nèi)容增加一個顯示更多的功能2010-08-08為jquery.ui.dialog 增加“自動記住關(guān)閉時的位置”的功能
筆者在項目中使用 jquery.ui.dialog 1.7.2時,當使用$("#d").dialog("open");時,dialog總是彈出在option中指定的位置;2009-11-11DataTables+BootStrap組合使用Ajax來獲取數(shù)據(jù)并且動態(tài)加載dom的方法(排序,過濾,分頁等)
Datatables是一款jquery表格插件。它是一個高度靈活的工具,可以將任何HTML表格添加高級的交互功能。這篇文章主要介紹了DataTables+BootStrap組合使用Ajax來獲取數(shù)據(jù)并且動態(tài)加載dom的方法(排序,過濾,分頁等),需要的朋友可以參考下2016-11-11jQuery實現(xiàn)的一個自定義Placeholder屬性插件
這篇文章主要介紹了jQuery實現(xiàn)的一個自定義Placeholder屬性插件,本文最后附有插件完整源碼,需要的朋友可以參考下2014-08-08jquery 圖片Silhouette Fadeins漸顯效果
經(jīng)常漂流在css-tricks看到這篇文章,就順便搬了過來,下面譯文都是用css-tricks口吻來描述的。2010-02-02jquery實現(xiàn)根據(jù)瀏覽器窗口大小自動縮放圖片的方法
這篇文章主要介紹了jquery實現(xiàn)根據(jù)瀏覽器窗口大小自動縮放圖片的方法,涉及jquery操作頁面元素屬性與樣式的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-07-07推薦40個簡單的 jQuery 導(dǎo)航插件和教程(下篇)
在下面的集合中,你會發(fā)現(xiàn)很多便利的 jQuery 導(dǎo)航插件和有用的教程,幫助你實現(xiàn)充滿吸引力的網(wǎng)站導(dǎo)航,讓你網(wǎng)站更有組織性和交互性2012-09-09