最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Jquery中的CheckBox、RadioButton、DropDownList的取值賦值實現(xiàn)代碼

 更新時間:2011年10月12日 21:07:59   作者:  
隨著Jquery的作用越來越大,使用的朋友也越來越多。在Web中,由于CheckBox、 Radiobutton 、 DropDownList等控件使用的頻率比較高,就關(guān)系到這些控件在Jquery中的操作問題
由于Jquery的版本更新很快,代碼的寫法也改變了許多,以下Jquery代碼適query1.4版本以上
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='rd2']").attr('checked','true');
或者
$("input[value='rd2']").attr('checked','true');
6.刪除Value值為rd2的Radio
$("input:radio[value='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為選中值:
$('select#sel option:last).attr('selected','true')
7. 根據(jù)索引值設(shè)置任意一個option為選中值:
$('select#sel')[0].selectedIndex =索引值;索引值=0,1,2....
8. 設(shè)置Value=4 的option為選中值:
$('select#sel').attr('value','4');
或者
$("select#sel option[value='4']").attr('selected', 'true');
9. 刪除Value=3的option:
$("select#sel option[value='3']").remove();
10.刪除第幾個option:
$(" select#sel option ").eq(索引值).remove();索引值=0,1,2....
如刪除第3個Radio:
$(" select#sel option ").eq(2).remove();
11.刪除第一個option:
$(" select#sel option ").eq(0).remove();
或者
$("select#sel option:first").remove();
12. 刪除最后一個option:
$("select#sel option:last").remove();
13. 刪除dropdownlist:
$("select#sel").remove();
14.在select后面添加一個option:
$("select#sel").append("<option value='6'>f</option>");
15. 在select前面添加一個option:
$("select#sel").prepend("<option value='0'>0</option>");
16. 遍歷option:
$(' select#sel option ').each(function (index, domEle) {
//寫入代碼
});
CheckBox

1. 獲取單個checkbox選中項(三種寫法):
$("input:checkbox:checked").val()
或者
$("input:[type='checkbox']:checked").val();
或者
$("input:[name='ck']:checked").val();
2. 獲取多個checkbox選中項:
$('input:checkbox').each(function() {
if ($(this).attr('checked') ==true) {
alert($(this).val());
}
});
3. 設(shè)置第一個checkbox 為選中值:
$('input:checkbox:first').attr("checked",'checked');
或者
$('input:checkbox').eq(0).attr("checked",'true');
4. 設(shè)置最后一個checkbox為選中值:
$('input:radio:last').attr('checked', 'checked');
或者
$('input:radio:last').attr('checked', 'true');
5. 根據(jù)索引值設(shè)置任意一個checkbox為選中值:
$('input:checkbox).eq(索引值).attr('checked', 'true');索引值=0,1,2....
或者
$('input:radio').slice(1,2).attr('checked', 'true');
6. 選中多個checkbox:
同時選中第1個和第2個的checkbox:
$('input:radio').slice(0,2).attr('checked','true');
7. 根據(jù)Value值設(shè)置checkbox為選中值:
$("input:checkbox[value='1']").attr('checked','true');
8. 刪除Value=1的checkbox:
$("input:checkbox[value='1']").remove();
9. 刪除第幾個checkbox:
$("input:checkbox").eq(索引值).remove();索引值=0,1,2....
如刪除第3個checkbox:
$("input:checkbox").eq(2).remove();
10.遍歷checkbox:
$('input:checkbox').each(function (index, domEle) {
//寫入代碼
});
11.全部選中
$('input:checkbox').each(function() {
$(this).attr('checked', true);
});
12.全部取消選擇:
$('input:checkbox').each(function () {
$(this).attr('checked',false);
});

相關(guān)文章

  • jquery下jstree簡單應(yīng)用 - v1.0

    jquery下jstree簡單應(yīng)用 - v1.0

    jquery下jstree簡單應(yīng)用,學習jstree的朋友可以參考下。
    2011-04-04
  • jquery 選擇器引擎sizzle淺析

    jquery 選擇器引擎sizzle淺析

    用jquery的大概有一年了,只知道$(selector),其內(nèi)部選擇器是如何實現(xiàn)并不完全不清晰,汗顏啊于是看了jquery的源碼,jquery用的選擇器的引擎是sizzle,感興趣的朋友可以了解下,或許本文對你有所幫助
    2013-02-02
  • jQuery獲取當前點擊的對象元素(實現(xiàn)代碼)

    jQuery獲取當前點擊的對象元素(實現(xiàn)代碼)

    下面小編就為大家?guī)硪黄猨Query獲取當前點擊的對象元素(實現(xiàn)代碼)。小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考,一起跟隨小編過來看看吧
    2016-05-05
  • 淺析Jquery操作select

    淺析Jquery操作select

    本文主要介紹了Jquery如何操作select,并對此做了詳細的注釋,具有很好的參考價值,需要的朋友可以看看
    2016-12-12
  • jQuery html()等方法介紹

    jQuery html()等方法介紹

    在jQuery里面對于一些HTML的元素操作都是很簡化的,這也是很多人選擇使用jQuery的原因。
    2009-11-11
  • jquery使用filter()控制子元素顯示隱藏

    jquery使用filter()控制子元素顯示隱藏

    一般元素下的多個指定子元素顯示隱藏效果,使用css中的選擇器:nth-child()、:nth-of-type(),但如果想使用JavaScript動態(tài)控制,就需要用到j(luò)query的filter()方法
    2023-08-08
  • jQuery總體架構(gòu)的理解分析

    jQuery總體架構(gòu)的理解分析

    jQuery總體架構(gòu)的理解,學習jquery的朋友可以參考下。
    2011-03-03
  • jQuery+Ajax+PHP+Mysql實現(xiàn)分頁顯示數(shù)據(jù)實例講解

    jQuery+Ajax+PHP+Mysql實現(xiàn)分頁顯示數(shù)據(jù)實例講解

    這是一個典型的Ajax應(yīng)用,在頁面上,您只需要點擊“下一頁”,數(shù)據(jù)區(qū)將自動加載對應(yīng)頁碼的數(shù)據(jù),重新刷新數(shù)據(jù)區(qū)。類似的效果在很多網(wǎng)站上應(yīng)用,尤其在一些需要展示大量圖片數(shù)據(jù)的網(wǎng)頁如淘寶商品列表頁,Ajax分頁效果讓您的網(wǎng)站數(shù)據(jù)加載顯得非常流暢。
    2015-09-09
  • 60個很實用的jQuery代碼開發(fā)技巧收集

    60個很實用的jQuery代碼開發(fā)技巧收集

    這篇文章主要介紹了60個很實用的jQuery代碼開發(fā)技巧收集,使用jquery的朋友可以參考下核心代碼的使用,需要的朋友可以參考下
    2014-12-12
  • 推薦10個超棒的jQuery工具提示插件

    推薦10個超棒的jQuery工具提示插件

    本文為大家收集了10個非常酷的 jQuery 工具提示(Tooltip)插件,希望大家能喜歡
    2011-10-10

最新評論

双鸭山市| 湄潭县| 桑日县| 磐安县| 张北县| 长顺县| 鄄城县| 双流县| 平利县| 新巴尔虎右旗| 南阳市| 汉阴县| 惠水县| 灵丘县| 威宁| 乌海市| 利川市| 英山县| 垫江县| 宁城县| 来凤县| 米脂县| 伊金霍洛旗| 类乌齐县| 彭泽县| 手游| 大悟县| 金塔县| 朝阳县| 彭泽县| 青铜峡市| 昌邑市| 商都县| 常熟市| 突泉县| 扎鲁特旗| 十堰市| 牡丹江市| 祁阳县| 桂阳县| 虎林市|