联系我们
简单又实用的WordPress网站制作教学
当前位置:网站首页 > 网页前端技术 > 正文

jQuery操作select下拉框的text值和value值的方法 - Web前端

作者:98wpeu发布时间:2026-06-29分类:网页前端技术浏览:5


导读:1、JQuery获取当前选中select的text值varcheckText=$("#slc1").find("option:selected").text();2、jQue...
1、JQuery获取当前选中select的text值

var checkText=$("#slc1").find("option:selected").text();

2、jQuery获取当前选中select的value值

var checkValue=$("#slc1").val();

3、jquery获取当前选中select的索引值

var index=$("#slc1 ").get(0).selectedIndex;

4、jquery设置索引值为1的项为当前选中项

$("#slc1 ").get(0).selectedIndex=1;

5、JQuery设置value值2的项为当前选中项

$("#slc1 ").val(2);

6、jquery设置text值为"青藤园"的项为当前选中项

$("#slc1 option[text='青园w']").attr("selected",true);

7、为指定select下拉框追加一个option(追加到在末尾)

$("#slc2").append(""+i+"");

8、为制定select下拉框插入一个option(插入到第一个位置)

$("#slc2").prepend("请选择");

9、jquery删除select下拉框的最后一个option

$("#slc2 option:last").remove();

标签:操作下拉框方法Webtextselect


网页前端技术排行
最近发表
网站分类
标签列表