jQuery操作 input type=checkbox的實(shí)現(xiàn)代碼
更新時(shí)間:2012年06月14日 23:17:19 作者:
jQuery操作 input type=checkbox的實(shí)現(xiàn)代碼,需要的朋友可以參考下,這邊腳本之家推薦大家看我們以前發(fā)布的文章
復(fù)制代碼 代碼如下:
<input type="checkbox">:
2012歐洲杯"死亡之組"小組出線的國家隊(duì)是:<br>
<input type="checkbox" name="nation" value="Germany">德國
<input type="checkbox" name="nation" value="Denmark">丹麥
<input type="checkbox" name="nation" value="Holland">荷蘭
<input type="checkbox" name="nation" value="Portugal">葡萄牙
1、小組第一名和第二名出線,所以要限制只能選兩項(xiàng)。
復(fù)制代碼 代碼如下:
var len = $("input[name='nation']:checked").length;
if(len==0) {
alert("請選擇出線的國家隊(duì)!");
return false;
}else if(len<2) {
alert("請選擇兩個(gè)國家隊(duì)!");
return false;
}else if(len>2) {
alert("只能選擇兩個(gè)國家隊(duì)!");
return false;
}else {
return true;
}
2、遍歷已選擇的國家隊(duì)。
復(fù)制代碼 代碼如下:
$("input[name='nation']:checked").each(function(){
alert("已選擇的國家隊(duì): "+$(this).val());
});
3、取消所有選中的國家隊(duì)。
復(fù)制代碼 代碼如下:
$("input[name='nation']:checked").attr("checked",false);
4、指定選中兩個(gè)國家隊(duì)。
復(fù)制代碼 代碼如下:
$("input[name='nation'][value='Germany']").attr("checked",true);
$("input[name='nation'][value='Holland']").attr("checked",true);
5、禁止選擇國家隊(duì)。
復(fù)制代碼 代碼如下:
$("input[name='nation']").attr("disabled",true);
6、允許選擇國家隊(duì)。
復(fù)制代碼 代碼如下:
$("input[name='nation']").attr("disabled",false);
7、選中索引為偶數(shù)或者奇數(shù)的國家隊(duì)(索引是從0開始)。
復(fù)制代碼 代碼如下:
//選中索引為偶數(shù)的國家隊(duì)
$("input[name='nation']:even").attr("checked",true);
//選中索引為奇數(shù)的國家隊(duì)
$("input[name='nation']:odd").attr("checked",true);
$("input[name='nation']:even").attr("checked",true);
//選中索引為奇數(shù)的國家隊(duì)
$("input[name='nation']:odd").attr("checked",true);
相關(guān)文章
jquery實(shí)現(xiàn)無刷新驗(yàn)證碼的簡單實(shí)例
下面小編就為大家?guī)硪黄猨query實(shí)現(xiàn)無刷新驗(yàn)證碼的簡單實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-05-05jquery 跳到頂部和底部動(dòng)畫2句代碼簡單實(shí)現(xiàn)
使用2句代碼簡單實(shí)現(xiàn)jquery動(dòng)畫的跳到頂部和底部;當(dāng)點(diǎn)擊頂部按鈕的時(shí)候,執(zhí)行方法,scrollTop屬性獲取選中標(biāo)簽距滾動(dòng)條的距離,具體的實(shí)現(xiàn)如下,感興趣的朋友可以參考下2013-07-07jQuery實(shí)現(xiàn)可以控制圖片旋轉(zhuǎn)角度效果(附demo源碼下載)
這篇文章主要介紹了jQuery實(shí)現(xiàn)可以控制圖片旋轉(zhuǎn)角度效果,可實(shí)現(xiàn)通過下方的滑塊拖動(dòng)控制圖片旋轉(zhuǎn)的功能,涉及jQuery操作頁面元素樣式動(dòng)態(tài)變換的技巧,并附帶demo源碼供讀者下載,需要的朋友可以參考下2016-01-01jQuery點(diǎn)擊導(dǎo)航欄選中更換樣式的實(shí)現(xiàn)代碼
這篇文章主要介紹了jQuery點(diǎn)擊導(dǎo)航欄選中更換樣式的實(shí)現(xiàn)代碼,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-01-01jQuery實(shí)現(xiàn)的模擬彈出窗口功能示例
這篇文章主要介紹了jQuery實(shí)現(xiàn)的模擬彈出窗口功能,結(jié)合實(shí)例形式分析了jQuery彈出窗口的初始化、坐標(biāo)、背景設(shè)置等相關(guān)操作技巧,需要的朋友可以參考下2016-11-11Jquery和angularjs獲取check框選中的值的方法匯總
本文分別通過具體的實(shí)例向大家展示了jquery和angularjs獲取獲取check框選中的值的方法,非常的簡單實(shí)用,有需要的小伙伴可以參考下2016-01-01