各種選擇框jQuery的選中方法(實(shí)例講解)
select下拉列表的選中方法是:$("slect option:eq(1)").attr("selected",true);//選中第二個(gè)option
chekbox的選中方法:$("[value=check1"]:checkbox).attr("checked",true);
radio的選中方法:$("[value=radio2"]:radio).attr("checked",true);
以上是簡寫,重要的是看代碼:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>3-10-4</title> <style type="text/css"> .test{ font-weight:bold; color : red; } .add{ font-style:italic; } </style> <!-- 引入jQuery --> <script src="../../scripts/jquery-1.3.1.js" type="text/javascript"></script> <script type="text/javascript"> //<![CDATA[ $(function(){ //設(shè)置單選下拉框選中 $("input:eq(0)").click(function(){ $("#single option").removeAttr("selected"); //移除屬性selected $("#single option:eq(1)").attr("selected",true); //設(shè)置屬性selected }); //設(shè)置多選下拉框選中 $("input:eq(1)").click(function(){ $("#multiple option").removeAttr("selected"); //移除屬性selected $("#multiple option:eq(2)").attr("selected",true);//設(shè)置屬性selected $("#multiple option:eq(3)").attr("selected",true);//設(shè)置屬性selected }); //設(shè)置單選框和多選框選中 $("input:eq(2)").click(function(){ $(":checkbox").removeAttr("checked"); //移除屬性checked $(":radio").removeAttr("checked"); //移除屬性checked $("[value=check2]:checkbox").attr("checked",true);//設(shè)置屬性checked $("[value=check3]:checkbox").attr("checked",true);//設(shè)置屬性checked $("[value=radio2]:radio").attr("checked",true);//設(shè)置屬性checked }); }); //]]> </script> </head> <body> <input type="button" value="設(shè)置單選下拉框選中"/> <input type="button" value="設(shè)置多選下拉框選中"/> <input type="button" value="設(shè)置單選框和多選框選中"/> <br/><br/> <select id="single"> <option>選擇1號(hào)</option> <option>選擇2號(hào)</option> <option>選擇3號(hào)</option> </select> <select id="multiple" multiple="multiple" style="height:120px;"> <option selected="selected">選擇1號(hào)</option> <option>選擇2號(hào)</option> <option>選擇3號(hào)</option> <option>選擇4號(hào)</option> <option selected="selected">選擇5號(hào)</option> </select> <br/><br/> <input type="checkbox" value="check1"/> 多選1 <input type="checkbox" value="check2"/> 多選2 <input type="checkbox" value="check3"/> 多選3 <input type="checkbox" value="check4"/> 多選4 <br/> <input type="radio" value="radio1" name="a"/> 單選1 <input type="radio" value="radio2" name="a"/> 單選2 <input type="radio" value="radio3" name="a"/> 單選3 </body> </html>
以上這篇各種選擇框jQuery的選中方法(實(shí)例講解)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
- Chosen 基于jquery的選擇框插件使用方法
- jQuery實(shí)現(xiàn)選中彈出窗口選擇框內(nèi)容后賦值給文本框的方法
- 基于JQuery的Select選擇框的華麗變身
- 基于jquery實(shí)現(xiàn)select選擇框內(nèi)容左右移動(dòng)添加刪除代碼分享
- 基于jQuery下拉選擇框插件支持單選多選功能代碼
- jquery通過select列表選擇框?qū)Ρ砀駭?shù)據(jù)進(jìn)行過濾示例
- jquery實(shí)現(xiàn)select選擇框內(nèi)容左右移動(dòng)代碼分享
- Jquery多選下拉列表插件jquery multiselect功能介紹及使用
- 用jquery實(shí)現(xiàn)下拉菜單效果的代碼
- 用jquery實(shí)現(xiàn)的一個(gè)超級(jí)簡單的下拉菜單
- jQuery模擬12306城市選擇框功能簡單實(shí)現(xiàn)方法示例
相關(guān)文章
jQuery模擬物體自由落體運(yùn)動(dòng)(附演示與demo源碼下載)
這篇文章主要介紹了jQuery模擬物體自由落體運(yùn)動(dòng)的方法,并附帶了效果演示與demo源碼下載,可真是模擬出球體自由落體運(yùn)動(dòng)及動(dòng)能損耗的運(yùn)動(dòng)過程,需要的朋友可以參考下2016-01-01Jquery中.bind()、.live()、.delegate()和.on()之間的區(qū)別詳解
在我們?nèi)粘i_發(fā)中經(jīng)常會(huì)使用到.bind()、.live()、.delegate()和.on(),有些同學(xué)會(huì)對(duì)這四者存在一些疑慮,所以下面這篇文章主要給大家介紹了關(guān)于Jquery中.bind()、.live()、.delegate()和.on()之間區(qū)別的相關(guān)資料,需要的朋友可以參考借鑒。2017-08-08jQuery+Datatables實(shí)現(xiàn)表格批量刪除功能【推薦】
這篇文章主要介紹了jQuery+Datatables實(shí)現(xiàn)表格批量刪除功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-10-10使用jQuery實(shí)現(xiàn)頁面定時(shí)彈出廣告效果
這篇文章主要介紹了使用jQuery實(shí)現(xiàn)頁面定時(shí)彈出廣告效果,需要的朋友可以參考下2017-08-08輕量級(jí)網(wǎng)頁遮罩層jQuery插件用法實(shí)例
這篇文章主要介紹了輕量級(jí)網(wǎng)頁遮罩層jQuery插件用法,實(shí)例分析了jquery遮罩層插件的定義、功能及使用方法,非常簡單實(shí)用,需要的朋友可以參考下2015-07-07jQuery點(diǎn)擊tr實(shí)現(xiàn)checkbox選中的方法
jQuery點(diǎn)擊tr實(shí)現(xiàn)checkbox選中的方法,需要的朋友可以參考一下2013-03-03基于jquery實(shí)現(xiàn)后臺(tái)左側(cè)菜單點(diǎn)擊上下滑動(dòng)顯示
一個(gè)左側(cè)菜單點(diǎn)擊是可以上下滑動(dòng),簡潔時(shí)尚,復(fù)制即可使用,感興趣的朋友可以參考下哈,希望對(duì)你有所幫助2013-04-04