jQuery的select取值、选择基本操作

关于jQuery的select取值、选择基本操作
1.清空(意味着情况select中的所用option,即文本的值)
$("#selectId").empty();
$("#selectId").html("");
$("#selectId").find(“option”).remove();
document.getElementById(“selectId”).options.length = 0;
document.formName.selectName.options.length = 0;
document.getElementById(“selectId”).innerHTML = “”;
2.获取选中默认值
$("#selectId").find(“option:selected”).val();
$(’#selectId option:selected’).val();
3.获取选中文本值
$("#selectId").find(“option:selected”).text();
KaTeX parse error: Expected 'EOF', got '#' at position 3: ('#̲selectId option…(’’);
for(var i=0;i<5;i++){
item.append(’’+i+’’);
}
5.设置一个select为请选择状态
$("#selectId").find(“option[value=’’]”).attr(“selected”,true);
6.jQuery添加/删除Select的Option项:
$("#select_id").append(“Text”); //为Select追加一个Option(下拉项)
$("#select_id").prepend(“请选择”); //为Select插入一个Option(第一个位置)
$("#select_id option:last").remove(); //删除Select中索引值最大Option(最后一个)
$("#select_id option[index=‘0’]").remove(); //删除Select中索引值为0的Option(第一个)
$("#select_id option[value=‘3’]").remove(); //删除Select中Value='3’的Option
$("#select_id option[text=‘4’]").remove(); //删除Select中Text='4’的Option

事件
7.change 改变下拉时触发;
KaTeX parse error: Expected 'EOF', got '#' at position 3: ("#̲select_id").cha…(this).val());
);
补充:因为页面翻页也是使用Ajax技术进行异步处理,当翻页后,原写法将失效,此时应该使用如下代码进行执行:
KaTeX parse error: Expected 'EOF', got '#' at position 25: …).on("change",'#̲select_id',func…(this).val());
});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值