一 、Select

jQuery获取Select选择的Text和Value:

1. $("#select_id").change(function(){//code...}); //为Select添加事件,当选择其中一项时触发

2. var checkText=$("#select_id").find("option:selected").text(); //获取Select选择的Text

3. var checkValue=$("#select_id").val(); //获取Select选择的Value

4. var checkIndex=$("#select_id ").get(0).selectedIndex; //获取Select选择的索引值

5. var maxIndex=$("#select_id option:last").attr("index"); //获取Select最大的索引值

jQuery设置Select选择的Text和Value:

1. $("#select_id ").get(0).selectedIndex=1; //设置Select索引值为1的项选中

2. $("#select_id ").val(4); //设置Select的Value值为4的项选中

3. $("#select_id option[text='jQuery']").attr("selected", true); //设置Select的Text值为jQuery的项选中

jQuery添加/删除Select的Option项:

1. $("#select_id").append("<option value='Value'>Text</option>"); //为Select追加一个Option(下拉项)

2. $("#select_id").prepend("<option value='0'>请选择</option>"); //为Select插入一个Option(第一个位置)

3. $("#select_id option:last").remove(); //删除Select中索引值最大Option(最后一个)

4. $("#select_id option[index='0']").remove(); //删除Select中索引值为0的Option(第一个)

5. $("#select_id option[value='3']").remove(); //删除Select中Value='3'的Option

6. $("#select_id option[text='4']").remove(); //删除Select中Text='4'的Option

7. $("#SelectID").remove(); //删除所有项

二、Checkbox

全选/取消

jQuery.attr 获取/设置对象的属性值,如:

$("input[name='chk_list']").attr("checked"); //读取所有name为'chk_list'对象的状态(是否选中)

$("input[name='chk_list']").attr("checked",true); //设置所有name为'chk_list'对象的checked为true

$("#img_1").attr("src","test.jpg"); //设置ID为img_1的<img>src的值为'test.jpg'

$("#img_1").attr("src"); //读取ID为img_1的<img>src值

下面的代码是获取上面实例中选中的checkbox的value值:

<script type="text/javascript">

$(document).ready(function() {

var arrChk=$("input[name='chk_list'][checked]");

$(arrChk).each(function(){

window.alert(this.value);

});

});

</script>

1,获取checkbox的value

$("#checkboxID").value或$("input[type='checkbox']").eq(n).attr("checked").value

2,设置选中项

$("input[type='checkbox']").eq(1).attr("checked")//设置第一个checkbox为选中的项

3,删除所有checkbox

$("input[type='checkbox']").remove()

4,checkbox方法

$(document).ready(function() {

var check = $("input[type='checkbox']");

check.each(function(n) {

check.eq(n).bind("click", function() {

if (check.eq(n).attr("checked") != false) {

var value = check.eq(n).val();

alert(value);

}

else {

alert(check.eq(n).attr("checked"));

}

})

});

});

三、radio

1,获取选中的value值

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

2,设置指定的项为当前选中项

$("input[type='radio']").eq(1).attr("checked", true);//设置第二项为选中项

$("input[type='radio'][value='值']").attr("checked, true");

3,解决多个Radio

$("input[type='radio'][@name='rdoTest2']").eq(0).attr("checked", true);

Jquery操作select、checkbox、radio详细讲解的更多相关文章

  1. jquery 操作select,checkbox,radio (整理)

    在工作中经经常使用到select,checkbox,radio,今天有点空暇就整理一下,免得以后用的时候还要又一次找. 操作select下拉框 -- 获取值或选中项: 1, $("#sele ...

  2. JQuery操作select checkbox radio总结

    JQuery是一个非常强大的工具,所以我必须找到它最方便的方法,嘻嘻 Select CRUD: Select搜: 1.val值: $("#selectid").val();     ...

  3. Jquery操作select,radio,input,p之类

    select的操作 变化后触发操作 $("#txtaddprojecturl").change(function(){ $("#addprojectname") ...

  4. jQuery设置 select、radio、checkbox 默认选中的值

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. JQuery操作select下拉框

    JQuery操作select下拉框 获取Select选择的Text和Value $("#select_id").change(function(){//code...}); //为 ...

  6. jquery插件分类与编写详细讲解

    jquery插件分类与编写详细讲解 1. 插件种类 插件其实就是对现有的方法(或者叫函数)做一个封装,方便重用提高开发效率.   jQeury主要有2种类型   1)实例对象方法插件 开发能让所有的j ...

  7. jquery操作select下拉框的各种方法,获取选中项的值或文本,根据指定的值或文本选中select的option项等

    简介jquery里对select进行各种操作的方法,如联动.取值.根据值或文本来选中指定的select下拉框指定的option选项,读取select选中项的值和文本等. 这一章,站长总结一下jquer ...

  8. Jquery操作select,左右移动,双击移动 取到所有option的值

    $(function () { function MoveItem(fromId, toId) { $("#" + fromId + " option:selected& ...

  9. ThinkPHP第二十六天(JQuery操作select,SESSION和COOKIE)

    1.JQuery操作select,假设<select id="my"> A:双击选项<option>事件,应该是select的dbclick事件. B:获得 ...

  10. js与jQuery操作select大全

    Js操作Select是很常见的,也是比较实用的,每一次操作select的时候,总是要出来翻一下资料,不如自己总结一下,以后就翻这里了. 一.js操作select部分 判断select选项中 是否存在V ...

随机推荐

  1. RxJava RxAndroid【简介】

    资源 RxJava:https://github.com/ReactiveX/RxJava RxAndroid :https://github.com/ReactiveX/RxAndroid 官网:h ...

  2. ExcelApplication 另存Excel的SaveAs函数

    procedure SaveAs(const Filename: WideString; FileFormat: OleVariant; Password: OleVariant; WriteResP ...

  3. iOS 不同类之间的传值

    iOS是面向对象开发的,有很多不同的类,很多时候会遇到类与类之间的"交流"需求,比如通知.传递数值等等,(通知可以用nsnotificationcenter来做, 以后总结)下面主 ...

  4. poi大数据将excel2007导入数据库

    package com.jeeframe.cms.updata.service.impl; import java.io.IOException; import java.io.InputStream ...

  5. Android单位度量

    px(像素):屏幕上的点. in(英寸):长度单位.mm(毫米):长度单位.pt(磅):1/72英寸.dp(与密度无关的像素):一种基于屏幕密度的抽象单位.在每英寸160点的显示器上,1dp = 1p ...

  6. Spring4.0学习笔记(12) —— JDBCTemplate 操作数据库

    整体配置 1.配置xml文件 <beans:beans xmlns="http://www.springframework.org/schema/mvc" xmlns:xsi ...

  7. memcache锁

    锁的使用,一般情况是针对并发或者我们希望程序(crontab的job)串行处理,我们加锁的办法有很多,像文件锁,数据库锁,或者memcache锁,这里关注一下memcache锁,针对memcache锁 ...

  8. Linux文本操作三大利器总结:sed、awk、grep

    grep:(去除一行中需要的信息,同类与cut) grep全称是Global Regular Expression Print #常规用法 # grep -n root /etc/passwd :ro ...

  9. NET Core 数据保护2

    ASP.NET Core 数据保护(Data Protection 集群场景)[下]   前言 接[中篇],在有一些场景下,我们需要对 ASP.NET Core 的加密方法进行扩展,来适应我们的需求, ...

  10. javaWeb中一个按钮提交两个表单

    一个按钮提交两个表单,有时候会用到,一般会很容易想到使用 onclick="document.form1.submit();document.form2.submit();" 的方 ...