jQuery 操作 radio、select、checkbox
<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的更多相关文章
- [转]jQuery操作radio、checkbox、select 集合.
1.radio:单选框 html代码 <input type="radio" name="radio" id="radio1" val ...
- jQuery操作radio、checkbox、select 集合
1.radio:单选框 HTML代码: <input type="radio" name="radio" id="radio1" va ...
- jQuery操作radio、checkbox、select总结
1.radio:单选框 HTML代码: <input type="radio" name="radio" id="radio1" va ...
- jquery实用应用之jquery操作radio、checkbox、select
本文收集一些jquery的实用技巧,非常实用的哦,其中对radio.checkbox.select选中与取值的方法. 获取一组radio被选中项的值var item = $('input[@name= ...
- jQuery 操作input select,checkbox
input $("#add_device_owner_id").val() $("#add_device_owner_id").val("d" ...
- jquery的radio和checkbox的标签的操作集合
jquery的radio和checkbox的标签的操作集合: $("input[name='radio_name'][checked]").val(); //选择被选中Radio的 ...
- 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 ...
- jQuery 操作 input 之 checkbox
jQuery 操作 input 之 checkbox 一片 HTML 清单: <input type="checkbox" name="hobby" va ...
- 使用JQUERY操作Radio
发展中经常使用Radio为了实现用户的选择的影响.我在该项目中使用的一些JQUERY操作Radio该方法.这里分享,对于有需要的朋友参考的. 1.变化radio选择.引发一些结果 $("in ...
- jquery选中radio或checkbox的正确姿势
jquery选中radio或checkbox的正确姿势 Intro 前几天突然遇到一个问题,没有任何征兆的..,jquery 选中radio button单选框时,一直没有办法选中,后来查了许多资料, ...
随机推荐
- 创建 HelloWorld 项目
在 Eclipse 的导航栏中点击 File →New →Android Application Project ,此时会弹出创建 Android 项目的对话框.其中 Application Name ...
- maven生命周期理解
你可以仅仅调用clean来清理工作目录,仅仅调用site来生成站点.当然你也可以直接运行 mvn clean install site 运行所有这三套生命周期. 知道了每套生命周期的大概用途和相互关系 ...
- iOS 程序插件及功能动态更新思路
所用框架及语言 iOS客户端-Wax(开发愤怒的小鸟的连接Lua 和 Objc的框架),Lua,Objc, 服务端-Java(用于返回插件页面) 工具框架链接地址:Wax - https://gith ...
- 2018房地产沉思录 z
在中国,房价问题几乎有一个铁律:越调控越暴涨. 刚刚进入5月,全国各地发布的调控政策数量就已经超过了115个.仅4月份,全国各种房地产调控政策合计多达33次,25个城市与部门发布调控政策,其中海南.北 ...
- WordPress主题开发: 制作文章页面single.php
可以调用的文章内容: 调用文章标题:<?php the_title(); ?> 调用文章内容:<?php the_content(); ?> 调用文章摘要:<?php t ...
- docker 容器间网络配置
创建一个docker容器,docker系统会自动为该容器分配一个ip地址,通常是172.17开头. 我们可以在主机上用 docker inspect 命令 或者进入容器用ifconfig命令来查看容器 ...
- 也给我的E420拆机清清灰尘
用了两年,天气燥热,是得拆开清理下了,E430清理非常方便,拆开后面挡板就行,E420就麻烦很多,需要全部拆下,关于E420的拆机网上已经有非常详细的教程了,我这里做一些补充,有兴趣的同学欢迎参考. ...
- iPhone跳转的动画效果类型及实现方法 CATransition
实现iphone漂亮的动画效果主要有两种方法,一种是UIView层面的,一种是使用CATransition进行更低层次的控制, 第一种是UIView,UIView方式可能在低层也是使用CATransi ...
- mybatis之foreach用法
在做mybatis的mapper.xml文件的时候,我们时常用到这样的情况:动态生成sql语句的查询条件,这个时候我们就可以用mybatis的foreach了 foreach元素的属性主要有item, ...
- 学习笔记:Maven的ArcheType的学习笔记
摘要: Archetype是什么?它由哪些文件组成?如何创建和安装自己的archtype,如何使用自己创建的archetype? 一.Archetype是什么 Archetype其实就 ...