<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. 搭建《深入Linux内核架构》的Linux环境

    作者 彭东林 pengdonglin137@163.com 软件 Host: Ubuntu14.04 64 Qemu 2.8.0 Linux 2.6.24 busybox 1.24.2 gcc 4.4 ...

  2. ASP.NET Web API中展示实体Link相关的方面

    有时候,向服务端请求一个实体,我们希望返回如下的格式: links: [    href: http://localhost:8901/api/user/diaries/2013-08-17,    ...

  3. concat函數 函數concat 可以用來合拼兩個或以上的字串。

    12. “Mexico 墨西哥”的首都是”Mexico City”. 顯示所有國家名字,其首都是國家名字加上”City”. concat函數 函數concat 可以用來合拼兩個或以上的字串. : SE ...

  4. 怎样在xcode5中使用低版本sdk,解决兼容ios7ui问题

    问题 令人头疼的是,xcode每次升级都会使用最新版本的sdk,而且只有最新版本的sdk,对之前老版本的sdk都没有默认安装,这搞的最近我很头疼, 最近我升级到Xcode5.0版本,编译后运行后,在i ...

  5. blob转base64位 base64位转blob

    //**dataURL to blob** function dataURLtoBlob(dataurl) { var arr = dataurl.split(','), mime = arr[0]. ...

  6. Mysql 区分大小写进行查询

    区分大小写的查询: 因为MySQL的查询是默认不区分大小写的: 如果有些时候需要区分大小写,我们就需要binary这个关键字了. 可以这样用,在stud表中查找sname中带’j’ /’J’: 先不写 ...

  7. Java&C#语法差别

      Java C# 主类名与文件名 必须一致 可以不一致 命名空间导入方式 import关键字 using关键字 常量 final关键字 Const关键字 基本数据类型 C#中有无符号数,Java没有 ...

  8. executing external native build for cmake

    进一步调试的方法: 在Android studio下方打开terminal,然后: gradlew build --stacktrace

  9. Go语言之进阶篇服务器如何知道用户需要什么资源

    1.服务器如何知道用户需要什么资源 示例: package main import ( "fmt" "net" ) func main() { //监听 lis ...

  10. sharepoint list 文档上传和删除

    最近项目需要对sharepoint 文件操作,于是自己写了一个简单的工具类分享出来: namespace Microsoft.SharePoint { using System; using Syst ...