如何用jQuery获得select的值

1.获取第一个option的值

创新互联建站专注于莲湖企业网站建设,成都响应式网站建设公司,成都商城网站开发。莲湖网站建设公司,为莲湖等地区提供建站服务。全流程按需求定制设计,专业设计,全程项目跟踪,创新互联建站专业和态度为您提供的服务

$('#test option:first').val();

2.最后一个option的值

$('#test option:last').val();

3.获取第二个option的值

$('#test option:eq(1)').val();

4.获取选中的值

$('#test').val();

$('#test option:selected').val();

5.设置值为2的option为选中状态

$('#test').attr('value','2');

6.设置最后一个option为选中

$('#test option:last').attr('selected','selected');

$("#test").attr('value' , $('#test option:last').val());

$("#test").attr('value' , $('#test option').eq($('#test option').length - 1).val());

7.获取select的长度

$('#test option').length;

8.添加一个option

$("#test").append("");

$("").appendTo("#test");

9.添除选中项

$('#test option:selected').remove();

10.删除项选中(这里删除第一项)

$('#test option:first').remove();

11.指定值被删除

复制代码
$('#test option').each(function(){

if( $(this).val() == '5'){
$(this).remove();
}
});

$('#test option[value=5]').remove();
复制代码

12.获取第一个Group的标签

$('#test optgroup:eq(0)').attr('label');

13.获取第二group下面第一个option的值

$('#test optgroup:eq(1) : option:eq(0)').val();

14.根据option的值选中option

$("#sel option:contains('C')").prop("selected", true);


文章名称:如何用jQuery获得select的值
转载来于:http://csruizhi.cn/article/ieseso.html

其他资讯

Copyright © 2007-2024 成都优众联杰科技有限公司 All Rights Reserved 蜀ICP备2024116266号
友情链接: 高端网站设计 手机网站建设套餐 成都网站建设 重庆网站制作 外贸网站建设 四川成都网站建设 成都做网站建设公司 成都网站建设 成都网站制作 成都网站制作公司 营销网站建设 成都网站制作 温江网站设计 LED网站设计方案 上市集团网站建设 专业网站建设 成都网站建设公司 成都网站建设 高端定制网站设计 成都网站设计公司 成都网站设计公司 成都网站制作