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