基于jQuery選擇器之表單對象屬性篩選選擇器的實(shí)例

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title></title>
<link rel="stylesheet" href="imooc.css" rel="external nofollow" type="text/css">
<style>
input {
display: block;
margin: 10px;
padding: 10px;
}
</style>
<script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script>
</head>
<body>
<h2>子元素篩選選擇器</h2>
<h3>enabled、disabled</h3>
<form>
<input type="text" value="未設(shè)置disabled" />
<input type="text" value="設(shè)置disabled" disabled />
<input type="text" value="未設(shè)置disabled" />
</form>
<script type="text/javascript">
//查找所有input所有可用的(未被禁用的元素)input元素。
$("input:enabled").css("border", "2px groove red");
</script>
<script type="text/javascript">
//查找所有input所有不可用的(被禁用的元素)input元素。
$("input:disabled").css("border", "2px groove blue");
</script>
<h3>checked、selected</h3>
<form>
<input type="checkbox" checked="checked">
<input type="checkbox">
<input type="radio" checked>
<input type="radio">
<select name="garden" multiple="multiple">
<option>imooc</option>
<option selected="selected">慕課網(wǎng)</option>
<option>aaron</option>
<option selected="selected">博客園</option>
</select>
</form>
<script type="text/javascript">
//查找所有input所有勾選的元素(單選框,復(fù)選框)
//移除input的checked屬性
$("input:checked").removeAttr('checked')
</script>
<script type="text/javascript">
//查找所有option元素中,有selected屬性被選中的選項(xiàng)
//移除option的selected屬性
$("option:selected").removeAttr('selected')
</script>
</body>
</html>
注意:
在某些瀏覽器中,選擇器:checked可能會錯(cuò)誤選取到<option>元素,所以保險(xiǎn)起見換用選擇器input:checked,確保只會選取<input>元素
以上這篇jQuery選擇器之表單對象屬性篩選選擇器實(shí)例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
jQuery實(shí)現(xiàn)頁面內(nèi)錨點(diǎn)平滑跳轉(zhuǎn)特效的方法總結(jié)
通過jQuery實(shí)現(xiàn)頁面內(nèi)錨點(diǎn)平滑跳轉(zhuǎn)的方法很多,可以通過插件hovertreescroll實(shí)現(xiàn),也可以簡單的通過animate方法實(shí)現(xiàn),下面介紹這2種比較簡單的方法。2015-05-05
jQuery實(shí)現(xiàn)滾動到底部時(shí)自動加載更多的方法示例
這篇文章主要介紹了jQuery實(shí)現(xiàn)滾動到底部時(shí)自動加載更多的方法,涉及jQuery基于ajax動態(tài)操作頁面元素相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2018-02-02
jQuery實(shí)現(xiàn)區(qū)域打印功能代碼詳解
這篇文章主要介紹了jQuery實(shí)現(xiàn)區(qū)域打印功能代碼詳解的相關(guān)資料,非常不錯(cuò)具有參考借鑒價(jià)值,需要的朋友可以參考下2016-06-06
了解jQuery技巧來提高你的代碼(個(gè)人覺得那個(gè)jquery的手冊很不錯(cuò))
這個(gè)jQuery選擇器實(shí)驗(yàn)室非???,它能在線免費(fèi)使用,當(dāng)然你也能下來到本地離線使用。這個(gè)測試頁面包含復(fù)雜的HTML組合字段,然后你能嘗試預(yù)定義使用各種jQuery選擇器。如果這還不夠你也可以自定義選擇器2012-02-02
修改Jquery Dialog 位置的實(shí)現(xiàn)方法
下面小編就為大家?guī)硪黄薷腏query Dialog 位置的實(shí)現(xiàn)方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-08-08

