各種選擇框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);
以上是簡(jiǎn)寫(xiě),重要的是看代碼:
<!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í)例講解)就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
- Chosen 基于jquery的選擇框插件使用方法
- jQuery實(shí)現(xiàn)選中彈出窗口選擇框內(nèi)容后賦值給文本框的方法
- 基于JQuery的Select選擇框的華麗變身
- 基于jquery實(shí)現(xiàn)select選擇框內(nèi)容左右移動(dòng)添加刪除代碼分享
- 基于jQuery下拉選擇框插件支持單選多選功能代碼
- jquery通過(guò)select列表選擇框?qū)Ρ砀駭?shù)據(jù)進(jìn)行過(guò)濾示例
- jquery實(shí)現(xiàn)select選擇框內(nèi)容左右移動(dòng)代碼分享
- Jquery多選下拉列表插件jquery multiselect功能介紹及使用
- 用jquery實(shí)現(xiàn)下拉菜單效果的代碼
- 用jquery實(shí)現(xiàn)的一個(gè)超級(jí)簡(jiǎn)單的下拉菜單
- jQuery模擬12306城市選擇框功能簡(jiǎn)單實(shí)現(xiàn)方法示例
相關(guān)文章
JQuery動(dòng)態(tài)添加Select的Option元素實(shí)現(xiàn)方法
下面小編就為大家?guī)?lái)一篇JQuery動(dòng)態(tài)添加Select的Option元素實(shí)現(xiàn)方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-08-08
jquery實(shí)現(xiàn)加載更多"轉(zhuǎn)圈圈"效果(示例代碼)
這篇文章主要介紹了jquery實(shí)現(xiàn)加載更多"轉(zhuǎn)圈圈"效果,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-11-11
30個(gè)最佳jQuery Lightbox效果插件分享
Lightbox 應(yīng)該是最流行的圖片瀏覽效果了,常具有功能包括:自動(dòng)根據(jù)窗口的大小縮放圖片,模式窗口,幻燈片方式播放,內(nèi)容預(yù)加載,漸變等效果。2011-04-04
用jQuery模擬頁(yè)面加載進(jìn)度條的實(shí)現(xiàn)代碼
因?yàn)槲覀儫o(wú)法通過(guò)任何方法獲取整個(gè)頁(yè)面的大小和當(dāng)前加載了多少,所以想制作一個(gè)加載進(jìn)度條的唯一辦法就是模擬。那要怎么模擬呢2011-12-12

