jQuery select下拉基本属性

$("#select_id").change(function(){}); //1.为Select添加事件,当选择其中一项时触发    
var checkValue = $("#select_id").val(); //2.获取Select选中项的Value  
var checkText = $("#select_id :selected").text(); //3.获取Select选中项的Text   
var checkIndex = $("#select_id").attr("selectedIndex");//4.获取Select选中项的索引值,
或者:$("#select_id").get(0).selectedIndex; 
var maxIndex = $("#select_id :last").attr("index"); // 5.获取Select最大的索引值,
或者:$("#select_id :last").get(0).index;
 
$("#select_id").get(0).selectedIndex = 1; //1.设置Select索引值为1的项选中  
$("#select_id").val(4);  //2.设置Select的Value值为4的项选中
$("#select_id").attr("value","Normal“);
$("#select_id").get(0).value = value; //根据select的显示值来为select设值
var count=$("#select_id").get(0).options.length;
for(var i=0;i<count;i++){
if($("#select_id").get(0).options[i].text == text) 
{
$("#select_id").get(0).options[i].selected = true;        
break;  
}  
}
 
$("#select_id").append("<optionvalue='新增'>新增option</option>");// 1.为Select追加一个Option(下拉项)  
$("#select_id").prepend("<optionvalue='请选择'>请选择</option>");// 2.为Select插入一个Option(第一个位置)  
$("#select_id").get(0).remove(1);  //3.删除Select中索引值为1的Option(第二个)  
$("#select_id :last").remove();  //4.删除Select中索引值最大Option(最后一个)  
$("#select_id [value='3']").remove(); //5.删除Select中Value='3'的Option  
$("#select_id").empty();  // 6.清空下拉列表


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值