欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時(shí)間:2017年06月27日 08:11:45   投稿:jingxian  
下面小編就為大家?guī)硪黄鞣N選擇框jQuery的選中方法(實(shí)例講解)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧

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è)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論