JQuery 之 获取 radio选中值,select选中值

以下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为选中值:

原文地址:https://www.cnblogs.com/anyiz/p/10700756.html

时间: 2024-08-28 18:45:17

JQuery 之 获取 radio选中值,select选中值的相关文章

转-JQuery选择器及radio,checkbox,select取值和反选

jQuery 的选择器可谓之强大无比,这里简单地总结一下常用的元素查找方法 $("#myELement")    选择id值等于myElement的元素,id值不能重复在文档中只能有一个id值是myElement所以得到的是唯一的元素 $("div")           选择所有的div标签元素,返回div元素数组 $(".myClass")      选择使用myClass类的css的所有元素 $("*")        

Jquery常用操作:checkbox、select取值,radio、checkbox、select选中及其相关

常用Jquery操作:checkbox取值.select取值.radio选中.checkbox选中.select选中及其相关: 1.影藏页面元素 使用jquery真的很方便,比如要控制div的显示与隐藏,一句话就搞定了,请看下面使用说明. $("#id").show()表示display:block, $("#id").hide()表示display:none; $("#id").toggle()切换元素的可见状态.如果元素是可见的,切换为隐藏的

jquery radio取值,checkbox取值,select取值,radio选中,checkbox选中,select选中,及其相关

jquery radio取值,checkbox取值,select取值,radio选中,checkbox选中,select选中,及其相关 获取一组radio被选中项的值var item = $('input[@name=items][@checked]').val();获取select被选中项的文本var item = $("select[@name=items] option[@selected]").text();select下拉框的第二个元素为当前选中值$('#select_id'

easyui 》 radio取值,checkbox取值,select取值,radio选中,checkbox选中,select选中

获取一组radio被选中项的值var item = $('input[@name=items][@checked]').val();获取select被选中项的文本var item = $("select[@name=items] option[@selected]").text();select下拉框的第二个元素为当前选中值$('#select_id')[0].selectedIndex = 1;radio单选组的第二个元素为当前选中值$('input[@name=items]').g

JQuery设置获取下拉菜单选项的值 多实例

分享下JQuery如何设置获取下拉菜单某个选项的值,多种方法,值得收藏. JQuery获取和设置Select选项 获取Select :获取select 选中的 text :$(“#ddlRegType”).find(“option:selected”).text();获取select选中的 value:$(“#ddlRegType “).val();获取select选中的索引:$(“#ddlRegType “).get(0).selectedIndex;设置select:设置select 选中的

jquery怎么获取radio的值

使用jquery获取radio的值,最重要的是掌握jquery选择器的使用,在一个表单中我们通常是要获取被选中的那个radio 项的值,所以要加checked来筛选,比如有以下的一些radio项: 1.<input type="radio" name="testradio" value="jquery获取radio的值" />jquery获取radio的值 2.<input type="radio" name

jquery怎么获取radio选中的值

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Typ

Jquery页面在radio 初始化时候默认选中

网上找了很多资料,都是比较旧版本的方法,新版的jquery都已经抛弃了. 正确的代码是 1 $('input:radio[name="statusRadios"][value="normal"]').prop('checked', true); 2 $('input:radio[name=statusRadios]').filter('[value=banned]').prop('checked', true); //这个也可以 如果还使用了jquery的unifo

jquery修改获取radio的选中项

<input id="txtBeginDate" onclick="$('#divDate').css({'top':$('#txtBeginDate').offset().top+'px','left':$('#txtBeginDate').offset().left+'px'})" style="width:170px;padding:7px 10px;border:1px solid #ccc;margin-right:10px;"/