zl程序教程

您现在的位置是:首页 >  后端

当前栏目

js获取select标签选中值的两种方式

JS 获取 方式 标签 两种 SELECT 选中
2023-06-13 09:15:15 时间
复制代码代码如下:

varobj=document.getElementByIdx_x(”testSelect”);//定位idvarindex=obj.selectedIndex;//选中索引vartext=obj.options[index].text;//选中文本varvalue=obj.options[index].value;//选中值jQuery中获得选中select值第一种方式$("#testSelectoption:selected").text();//选中的文本$("#testSelectoption:selected").val();//选中的值$("#testSelect").get(0).selectedIndex;//索引第二种方式$("#tesetSelect").find("option:selected").text();//选中的文本…….val();…….get(0).selectedIndex;