随着Jquery的作用越来越大,使用的朋友也越来越多。在Web中,由于CheckBox、Radiobutton 、DropDownList等控件使用的频率比较高,就关系到这些控件在Jquery中的操作问题。由于Jquery的版本更新很快,代码的写法也改变了许多,以下Jquery代码适query1.4版本以上。

Radio

1.获取选中值,三种方法都可以:

$('input:radio:checked').val();

$("input[type='radio']:checked").val();

$("input[name='rd']:checked").val();

2.设置第一个Radio为选中值:

$('input:radio:first').attr('checked', 'checked');

或者

$('input:radio:first').attr('checked', 'true');

注:attr("checked",'checked')= attr("checked", 'true')= attr("checked", true)

3.设置最后一个Radio为选中值:

$('input:radio:last').attr('checked', 'checked');

或者

$('input:radio:last').attr('checked', 'true');

4.根据索引值设置任意一个radio为选中值:

$('input:radio').eq(索引值).attr('checked', 'true');索引值=0,1,2....

或者

$('input:radio').slice(1,2).attr('checked', 'true');

5.根据Value值设置Radio为选中值

$("input:radio[value=http://www.2cto.com/kf/201110/'rd2']").attr('checked','true');

或者

$("input[value=http://www.2cto.com/kf/201110/'rd2']").attr('checked','true');

6.删除Value值为rd2的Radio

$("input:radio[value=http://www.2cto.com/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.  设置第一个option为选中值:

$('select#sel option:first').attr('selected','true')

或者

$('select#sel')[0].selectedIndex = 0;

6.   设置最后一个option为选中值:

原文地址:http://www.hake.cc/a/biancheng/web/js/2011/1013/27444.html

获取radio的值的更多相关文章

  1. 使用jquery获取radio的值

     使用jquery获取radio的值,最重要的是掌握jquery选择器的使用,在一个表单中我们通常是要获取被选中的那个radio项的值,所以要加checked来筛选,比如有以下的一些radio项: ...

  2. jquery获取radio选中值及遍历

    使用jquery获取radio的值,最重要的是掌握jquery选择器的使用,在一个表单中我们通常是要获取被选中的那个radio项的值,所以要加checked来筛选,比如有以下的一些radio项:1.& ...

  3. jquery动态选中radio,获取radio选中值

    //动态选中radio值,1:表示radio的name 2:表示后台传过来的radio值$(":radio[name='1'][value='" + 2 + "']&qu ...

  4. Jquery 获取 radio选中值,select选中值

    随着Jquery的作用越来越大,使用的朋友也越来越多.在Web中,由于CheckBox.Radiobutton .DropDownList等控件使用的频率比较高,就关系到这些控件在Jquery中的操作 ...

  5. jquery中获取radio选中值的正确写法

    错误写法: //只在IE下有作用,其他浏览器均获取的为第一个单选框的值 $('input[type=radio]').val(); 正确写法为: //兼容所有浏览器写法 $('input[type=r ...

  6. jquery获取radio的值

    Html代码是 <label><input type="radio" name="proofing" value="1"& ...

  7. 纠正jQuery获取radio选中值的写法

    先看一段代码 <input type="radio" name="aaa" value="1" checked="true& ...

  8. 获取radio的值及重置radio

    获取:$('input[name=age]:checked').val(); 重置:$('input:radio[name=age]').prop('checked',false);

  9. Layui 获取 radio的值

    var OutInvoiceType = $('#OutInvoiceType input[checked]').val();   就可以获取到了.

随机推荐

  1. ipc 入侵步骤

    第一步:建立IPC隧道net use \\10.56.204.186\IPC$ "密码" /user:"用户"     第二步:映射对方c盘到本地z盘net u ...

  2. Xshell和VirtualBox虚机CentOS7的连接

    后面的不能连接问题,出处为 http://m.blog.csdn.net/article/details?id=52755571 1.centos7的ip ,这里的enp0s3相当于eth0,是一个默 ...

  3. Jdon框架开发指南

    Jdon框架快速开发指南 开发主要步骤如下: JdonFramework6.0以上两步开发见这里. 快速配置指南 新增/查询/修改/删除(CRUD); 批量查询和分页显示 本文Step By Step ...

  4. 背景background

    background简写:http://www.cnblogs.com/dunken/p/4380194.html

  5. node-canvas

    1.使用之前需要预先安装  Cairo 本人安装遇到各种各样的坑,可以参考这里来填坑:https://github.com/Automattic/node-canvas/wiki/Installati ...

  6. 单身福利来了:VR恋人为你量身定制一个女朋友

    相对于传统视频体验,VR视频给人带来了更加真实的体验.特别是对于单身狗来说,能在VR中拥有一个虚拟的恋人可谓是莫大的心灵安慰.近日,上海微雁文化传媒有限公司正式发布了首款养成类手机应用VR恋人. VR ...

  7. Java 四舍五入并小数点后保存两位,千分位分隔

    import java.text.DecimalFormat; public class FileTest {    public static void main(String[] args) {  ...

  8. c#的as关键字

    类型a  as 类型b   ,把类型a强制变为类型b

  9. [UWP小白日记-5]转换MVA学院的XML字幕为SRT

    开源地址:第二版开源地址GIT 暂时用不了了,在最新的WIN10 10586.494系统上回闪退,正在酝酿第二版 O(∩_∩)O哈哈~ 新版已经完工:第二版 地方MVA上好多教程,但是微软的所有中国网 ...

  10. Oracle 中的Top写法

    由于Oracle不支持select top 语句,所以在Oracle中经常是用order by 跟rownum的组合来实现select top n的查询.简单地说,实现方法如下所示:select 列名 ...