jquery表單對象屬性過濾選擇器實例分析
本文實例講述了jquery表單對象屬性過濾選擇器用法。分享給大家供大家參考。具體分析如下:
<!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=utf-8" /> <title>表單對象屬性過濾選擇器</title> <script src="jquery-1.6.2.min.js" type="text/javascript"></script> <script type="text/javascript"> $(function () { //=========舉例1=========================== //:enabled 用法: $(”input:enabled”) 返回值 集合元素 //說明: 匹配所有可用元素.意思是查找所有input中不帶有disabled=”disabled”的input.不為disabled, //當(dāng)然就為enabled啦. $("input:enabled").val("我是有效的按鈕"); //=========舉例2=========================== //:disabled 用法: $(”input:disabled”) 返回值 集合元素 //說明: 匹配所有不可用元素.與上面的那個是相對應(yīng)的. $("input:disabled").val("我是無效的按鈕"); //=========舉例3=========================== //:checked 用法: $(”input:checked”) 返回值 集合元素 //說明: 匹配所有選中的被選中元素(復(fù)選框、單選框等,不包括select中的option).這話說起來有些繞口. //...<1> 提取所有選中的name='love'的復(fù)選框 $("#btnTest").click(function () { ShowElements($("input[name='love']:checked")); //第一種寫法 //ShowElements($("[name='love']:checked")) //第二種寫法 }); //=========舉例4=========================== //:selected 用法: $(”select option:selected”) 返回值 集合元素 //說明: 匹配所有選中的option元素. //...<1> 所有name='city'的下拉框的選中項 $("#btnTest2").click(function () { ShowElements($("select[name='city'] option:selected")); }); //...<2> 所有name='prov'的下拉框的選中項 //$("#btnTest2").click(function () { // ShowElements($("select[name='prov'] option:selected")); //}); }); function ShowElements(arr) { //alert(arr.length); var output = ""; for (var i = 0; i < arr.length; i++) { if (output == "") { output = arr.eq(i).val(); } else { output += "," + arr.eq(i).val(); } } alert(output); } </script> </head> <body> <input type="button" disabled="disabled" value="button1" /> <input type="button" value="button2" /> <input type="button" value="button3" /> <input type="button" disabled="disabled" value="button4" /> <input type="button" id="btnTest" value="點擊我檢查復(fù)選框" /> <input type="checkbox" name="love" value="1" />足球 <input type="checkbox" name="love" value="2" />籃球 <input type="checkbox" name="love" value="3" />排球 <input type="checkbox" name="Other" value="3" />非愛好類<br /> 我是下拉框<input type="button" id="btnTest2" value="點擊我檢查下拉框" /> <select name="city"> <option value='beijing'>北京</option> <option value='shanghai'>上海</option> <option value='shenzhen'>深圳</option> </select> <select name="prov"> <option value='jiangxi'>江西省</option> <option value='shichuan'>四川省</option> <option value='guangdong'>廣東省</option> </select> </body> </html>
更多關(guān)于jquery選擇器相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jquery選擇器用法總結(jié)》
希望本文所述對大家的jQuery程序設(shè)計有所幫助。
相關(guān)文章
JQuery Tips(2) 關(guān)于$()包裝集你不知道的
包裝集總是面向集合的,需要的朋友可以參考下。2009-12-12基于JQuery實現(xiàn)相同內(nèi)容合并單元格的代碼
我們就中和下利用JQuery來和他一個table里面相同內(nèi)容的單元格,這里代碼跟大家分享下,希望對大家有用2011-01-01ASP.NET jQuery 實例3 (在TextBox里面阻止復(fù)制、剪切和粘貼事件)
在這講里,讓我們看下如何在ASP.NET Textbox里禁止復(fù)制、剪切和粘貼行為2012-01-01基于jQuery的為attr添加id title等效果的實現(xiàn)代碼
下面的例子是通過jquery為連接增加title描述的代碼,在當(dāng)前頁的連接上寫上,你好,現(xiàn)在在試驗連接文字的簡單描述。2011-04-04artDialog 4.1.5 Dreamweaver代碼提示/補全插件 附下載
artDialog是一個輕巧且高度兼容的javascript對話框組件,可讓你的網(wǎng)頁交互擁有桌面軟件般的用戶體驗2012-07-07