国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

各種選擇框jQuery的選中方法(實例講解)

2024-05-06 15:15:20
字體:
來源:轉載
供稿:網友

select下拉列表的選中方法是:$("slect option:eq(1)").attr("selected",true);//選中第二個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(){   //設置單選下拉框選中   $("input:eq(0)").click(function(){      $("#single option").removeAttr("selected"); //移除屬性selected      $("#single option:eq(1)").attr("selected",true); //設置屬性selected   });   //設置多選下拉框選中   $("input:eq(1)").click(function(){      $("#multiple option").removeAttr("selected"); //移除屬性selected      $("#multiple option:eq(2)").attr("selected",true);//設置屬性selected      $("#multiple option:eq(3)").attr("selected",true);//設置屬性selected   });   //設置單選框和多選框選中   $("input:eq(2)").click(function(){      $(":checkbox").removeAttr("checked"); //移除屬性checked      $(":radio").removeAttr("checked"); //移除屬性checked      $("[value=check2]:checkbox").attr("checked",true);//設置屬性checked      $("[value=check3]:checkbox").attr("checked",true);//設置屬性checked      $("[value=radio2]:radio").attr("checked",true);//設置屬性checked   }); }); //]]> </script></head><body>  <input type="button" value="設置單選下拉框選中"/>  <input type="button" value="設置多選下拉框選中"/>  <input type="button" value="設置單選框和多選框選中"/><br/><br/><select id="single"> <option>選擇1號</option> <option>選擇2號</option> <option>選擇3號</option></select><select id="multiple" multiple="multiple" style="height:120px;"> <option selected="selected">選擇1號</option> <option>選擇2號</option> <option>選擇3號</option> <option>選擇4號</option> <option selected="selected">選擇5號</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>            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 扬中市| 新宾| 隆回县| 白沙| 增城市| 龙游县| 桃源县| 旬阳县| 长治市| 菏泽市| 灵璧县| 博客| 新巴尔虎左旗| 鸡西市| 宁远县| 成武县| 溧水县| 水富县| 巴南区| 苏州市| 新乐市| 县级市| 莒南县| 张北县| 峨眉山市| 冕宁县| 娱乐| 蚌埠市| 东山县| 鲁甸县| 罗甸县| 隆德县| 西藏| 锡林浩特市| 寻乌县| 五指山市| 丹寨县| 涿鹿县| 门源| 渝北区| 日喀则市|