您的位置:首页 > Web前端 > JQuery

jquery select 选中 取值 赋值与jquery模拟select美化代码(1/6)

2013-09-05 20:23 666 查看
jquery select 选中 取值 赋值与jquery模拟select美化代码本教程主要是讲了关于jquery select 选中 取值 赋值与jquery模拟select美化了,讲了很多,如果你学习jquery也好,是想美化select也好,这款教程是有啊,关于query select 选中 取值 赋值是重点哦。jquery select 选中 取值 赋值与jquery模拟select美化代码
本教程主要是讲了关于jquery select 选中 取值 赋值与jquery模拟select美化了,讲了很多,如果你学习jquery也好,是想美化select也好,这款教程是有啊,关于query select 选中 取值 赋值是重点哦。

获取第一个option的值
$('#test option:first').val();
//最后一个option的值
$('#test option:last').val();
//获取第二个option的值
$('#test option:eq(1)').val();
//获取选中的值
$('#test').val();
$('#test option:selected').val();
//设置值为2的option为选中状态
$('#test').attr('value','2');
//设置第一个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());
//获取select的长度
$('#test option').length;
//添加一个option
$("#test").append("<option value='9'>ff</option>");
$("<option value='9'>ff</option>").appendto("#test");
//添除选中项
$('#test option:selected').remove();
//指定项选中
$('#test option:first').remove();
//指定值被删除
$('#test option').each(function(){
if( $(this).val() == '5'){
$(this).remove();
}
});
$('#test option[value=5]').remove(); 1 2 3 4 5 6
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: