Jquery獲取radio選中值實(shí)例總結(jié)
Radio
1.獲取選中值,三種方法都可以:
$('input:radio:checked').val(); $("input[type='radio']:checked").val(); $("input[name='rd']:checked").val();
2.設(shè)置第一個(gè)Radio為選中值:
$('input:radio:first').attr('checked', 'checked'); 或者 $('input:radio:first').attr('checked', 'true');
注:attr("checked",'checked')= attr("checked", 'true')= attr("checked", true)
3.設(shè)置最后一個(gè)Radio為選中值:
$('input:radio:last').attr('checked', 'checked'); 或者 $('input:radio:last').attr('checked', 'true');
4.根據(jù)索引值設(shè)置任意一個(gè)radio為選中值:
$('input:radio').eq(索引值).attr('checked', 'true');索引值=0,1,2.... 或者 $('input:radio').slice(1,2).attr('checked', 'true');
5.根據(jù)Value值設(shè)置Radio為選中值
$("input:radio[value=//www.dbjr.com.cn/kf/201110/'rd2']").attr('checked','true'); 或者 $("input[value=//www.dbjr.com.cn/kf/201110/'rd2']").attr('checked','true');
6.刪除Value值為rd2的Radio
$("input:radio[value=//www.dbjr.com.cn/kf/201110/'rd2']").remove();
7.刪除第幾個(gè)Radio
$("input:radio").eq(索引值).remove();索引值=0,1,2.... 如刪除第3個(gè)Radio:$("input:radio").eq(2).remove();
8.遍歷Radio
$('input:radio').each(function(index,domEle){ //寫(xiě)入代碼 });
DropDownList
1. 獲取選中項(xiàng):
獲取選中項(xiàng)的Value值:
$('select#sel option:selected').val();
或者
$('select#sel').find('option:selected').val();
獲取選中項(xiàng)的Text值:
$('select#seloption:selected').text();
或者
$('select#sel').find('option:selected').text();
2. 獲取當(dāng)前選中項(xiàng)的索引值:
$('select#sel').get(0).selectedIndex;
3. 獲取當(dāng)前option的最大索引值:
$('select#sel option:last').attr("index")
4. 獲取DropdownList的長(zhǎng)度:
$('select#sel')[0].options.length;
或者
$('select#sel').get(0).options.length;
5. 設(shè)置第一個(gè)option為選中值:
$('select#sel option:first').attr('selected','true')
或者
$('select#sel')[0].selectedIndex = 0;
6. 設(shè)置最后一個(gè)option為選中值
相關(guān)文章
基于jQuery實(shí)現(xiàn)的美觀星級(jí)評(píng)論打分組件代碼
這篇文章主要介紹了基于jQuery實(shí)現(xiàn)的美觀星級(jí)評(píng)論打分組件代碼,涉及jQuery回調(diào)函數(shù)及頁(yè)面元素屬性動(dòng)態(tài)操作的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-10-10jQuery判斷網(wǎng)頁(yè)是否已經(jīng)滾動(dòng)到瀏覽器底部的實(shí)現(xiàn)方法
最近做項(xiàng)目遇到這樣的需求,要求基于jq判斷網(wǎng)頁(yè)是否已經(jīng)滾動(dòng)到瀏覽器底部了,下面小編給大家分享實(shí)例代碼,需要的朋友參考下吧2017-10-10jQuery實(shí)現(xiàn)自動(dòng)調(diào)整字體大小的方法
這篇文章主要介紹了jQuery實(shí)現(xiàn)自動(dòng)調(diào)整字體大小的方法,涉及jQuery針對(duì)頁(yè)面屬性與樣式動(dòng)態(tài)操作的相關(guān)技巧,需要的朋友可以參考下2015-06-06基于jquery的從一個(gè)頁(yè)面跳轉(zhuǎn)到另一個(gè)頁(yè)面的指定位置的實(shí)現(xiàn)代碼(帶平滑移動(dòng)的效果)
從一個(gè)頁(yè)面跳轉(zhuǎn)到另一個(gè)頁(yè)面的指定位置 如果不帶平滑移動(dòng)的效果 很容易 加個(gè) 錨點(diǎn)就行了2011-05-05jQuery插件echarts去掉垂直網(wǎng)格線用法示例
這篇文章主要介紹了jQuery插件echarts去掉垂直網(wǎng)格線用法,結(jié)合實(shí)例形式對(duì)比分析了jQuery圖標(biāo)插件echarts針對(duì)垂直網(wǎng)格線的相關(guān)設(shè)置操作技巧,需要的朋友可以參考下2017-03-03jQuery簡(jiǎn)單實(shí)現(xiàn)向列表動(dòng)態(tài)添加新元素的方法示例
這篇文章主要介紹了jQuery簡(jiǎn)單實(shí)現(xiàn)向列表動(dòng)態(tài)添加新元素的方法,涉及jQuery事件響應(yīng)及頁(yè)面元素動(dòng)態(tài)操作相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2017-12-12jQuery簡(jiǎn)單實(shí)現(xiàn)隱藏以及顯示特效
這篇文章主要介紹了jQuery簡(jiǎn)單實(shí)現(xiàn)隱藏以及顯示特效,需要的朋友可以參考下2015-02-02