<!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="未設置disabled" /> <input type="text" value="設置disabled" disabled /> <input type="text" value="未設置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">慕課網</option> <option>aaron</option> <option selected="selected">博客園</option> </select> </form> <script type="text/javascript"> //查找所有input所有勾選的元素(單選框,復選框) //移除input的checked屬性 $("input:checked").removeAttr('checked') </script> <script type="text/javascript"> //查找所有option元素中,有selected屬性被選中的選項 //移除option的selected屬性 $("option:selected").removeAttr('selected') </script> </body> </html>
注意:
在某些瀏覽器中,選擇器:checked可能會錯誤選取到<option>元素,所以保險起見換用選擇器input:checked,確保只會選取<input>元素
以上這篇jQuery選擇器之表單對象屬性篩選選擇器實例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com