<script type="text/javascript">
$(function () {
一、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=gzmsg.com]").attr('checked','true');
或者
$("input[value=gzmsg.com").attr('checked','true'); 6.删除value值为gzmsg.com的radio
$("input:radio[value=gzmsg.com]").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){
//写入代码
}); 二、select
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为选中值: 三、checkbox
1、$(".chk").click(function(){}); 2、设置选中项
$("input[name='box']").attr("checked","checked"); 3.获取被选中的checkbox的值:
$("input[name='box'][checked]").each(function(){
if (true == $(this).attr("checked")) {
alert( $(this).attr('value') );
}
或者:
$("input[name='box']:checked").each(function(){
if (true == $(this).attr("checked")) {
alert( $(this).attr('value') );
} 4.获取未选中的checkbox的值:
$("input[name='box']").each(function(){
if ($(this).attr('checked') ==false) {
alert($(this).val());
}
}); 5.设置checkbox的value属性的值:
$(this).attr("value",值);
})
</script>

jQuery 操作 radio、select、checkbox的更多相关文章

  1. [转]jQuery操作radio、checkbox、select 集合.

    1.radio:单选框 html代码 <input type="radio" name="radio" id="radio1" val ...

  2. jQuery操作radio、checkbox、select 集合

    1.radio:单选框 HTML代码: <input type="radio" name="radio" id="radio1" va ...

  3. jQuery操作radio、checkbox、select总结

    1.radio:单选框 HTML代码: <input type="radio" name="radio" id="radio1" va ...

  4. jquery实用应用之jquery操作radio、checkbox、select

    本文收集一些jquery的实用技巧,非常实用的哦,其中对radio.checkbox.select选中与取值的方法. 获取一组radio被选中项的值var item = $('input[@name= ...

  5. jQuery 操作input select,checkbox

    input $("#add_device_owner_id").val() $("#add_device_owner_id").val("d" ...

  6. jquery的radio和checkbox的标签的操作集合

    jquery的radio和checkbox的标签的操作集合: $("input[name='radio_name'][checked]").val(); //选择被选中Radio的 ...

  7. JS中Float类型加减乘除 修复 JQ 操作 radio、checkbox 、select LINQ to SQL:Where、Select/Distinct LINQ to SQL Count/Sum/Min/Max/Avg Join

    JS中Float类型加减乘除 修复   MXS&Vincene  ─╄OvЁ  &0000027─╄OvЁ  MXS&Vincene MXS&Vincene  ─╄Ov ...

  8. jQuery 操作 input 之 checkbox

    jQuery 操作 input 之 checkbox 一片 HTML 清单: <input type="checkbox" name="hobby" va ...

  9. 使用JQUERY操作Radio

    发展中经常使用Radio为了实现用户的选择的影响.我在该项目中使用的一些JQUERY操作Radio该方法.这里分享,对于有需要的朋友参考的. 1.变化radio选择.引发一些结果 $("in ...

  10. jquery选中radio或checkbox的正确姿势

    jquery选中radio或checkbox的正确姿势 Intro 前几天突然遇到一个问题,没有任何征兆的..,jquery 选中radio button单选框时,一直没有办法选中,后来查了许多资料, ...

随机推荐

  1. Team Foundation Server (TFS) 2015 安装指导

    1. 概述 微软于8月6日发布了大家期待已久的TFS 2015正式版, https://www.visualstudio.com/en-us/news/tfs2015-vs.aspx ,新版本包含的大 ...

  2. 理解 block

    开始:Block 简介 Block 是 iOS 4.0 和 Mac OSX 10.6 引入的一个新特性. Block 可以极大的简化代码. 他们可以帮助你减少代码, 减少对代理的依赖, 并且写出更加简 ...

  3. Cocos2d-x之CCMenu

    from://http://blog.linguofeng.com/archive/2012/11/14/cocos2d-x-CCMenu.html Cocos2d-x之CCMenu Cocos2dx ...

  4. Reflector_8.3.0.93_安装文件及破解工具

    Reflector_8.3.0.93_安装文件及破解工具 下载地址:http://pan.baidu.com/s/1jGwsYYM   约 8.9MB

  5. LeetCode——Convert Sorted List to Binary Search Tree

    Given a singly linked list where elements are sorted in ascending order, convert it to a height bala ...

  6. WCF:该不该用枚举值

    WCF支持枚举,不过在个别场景下会出现服务消费失败,如:传递或返回的枚举值(本质是int或其它)没有在枚举中定义.这种异常还很难定位,出现这种情况一般是因为BUG,因此简单的放弃使用枚举可能不是一个明 ...

  7. Linux的命名空间详解--Linux进程的管理与调度(二)

    转自:http://blog.csdn.net/gatieme/article/details/51383322 日期 内核版本 架构 作者 GitHub CSDN 2016-05-12 Linux- ...

  8. 【转】Itunes Connect新版本如何提交应用

    本文系转载,版权归原作者所有(原文链接>>). How do I submit my app to iTunes connect? To submit your app to iTunes ...

  9. http和https的区别与联系

    超文本传输协议HTTP协议被用于在Web浏览器和网站服务器之间传递信息,HTTP协议以明文方式发送内容,不提供任何方式的数据加密,如果攻击者截取了Web浏览器和网站服务器之间的传输报文,就可以直接读懂 ...

  10. docker 日志清理与设置

    清空 cat /dev/null >json.log docker-compose nginx: image: nginx:1.12.1 restart: always logging: dri ...