jQuery Select的操作集合
jQuery Select的操作集合
1. $("#select_id").change(function(){... }); //为select添加事件,当选择其中一项时触发
2. $("#select_id").find("option:selected").text(); //获取select选中的Text
3. $("#select_id").val(); //获取Select选中的Value
4. $("#select_id ").get(0).selectedIndex; //获取Select选中的索引值
5. $("#select_id option:last").attr("index"); //获取Select最大的索引值
6.$("#select_id ").get(0).selectedIndex=1; //设置Select索引值为1的项选中
7. $("#select_id ").val(4); //设置Select的Value值为4的项选中
8. $("#select_id option[text='jQuery']").attr("selected", true); //设置Select的Text值为jQuery的项选中
$("#tradeType option[value='1']").attr("selected", true); //设置select的value值为1时被选中
9.$("#select_id").append("<option value='Value'>Text</option>"); //为Select追加一个Option(下拉项)
10. $("#select_id").prepend("<option value='0'>请选择</option>"); //为Select插入一个Option(第一个位置)
11. $("#select_id option:last").remove(); //删除Select中索引值最大Option(最后一个)
12. $("#select_id option[index='0']").remove(); //删除Select中索引值为0的Option(第一个)
13. $("#select_id option[value='3']").remove(); //删除Select中Value='3'的Option
14. $("#select_id option[text='4']").remove(); //删除Select中Text='4'的Option
15.遍历select
$("#typeId option").each(function(){
if($(this).text()=="游戏娱乐"){
$(this).attr("selected", true);
}
});
16.$("#select_id").empty();
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)