Home  >  Article  >  Web Front-end  >  js获取select标签选中值的两种方式_javascript技巧

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

WBOY
WBOYOriginal
2016-05-16 17:04:401112browse
复制代码 代码如下:

var obj = document.getElementByIdx_x(”testSelect”); //定位idvar index = obj.selectedIndex; // 选中索引var text = obj.options[index].text; // 选中文本var value = obj.options[index].value; // 选中值jQuery中获得选中select值第一种方式$('#testSelect option:selected').text();//选中的文本$('#testSelect option:selected') .val();//选中的值$("#testSelect ").get(0).selectedIndex;//索引 第二种方式$("#tesetSelect").find("option:selected").text();//选中的文本…….val();…….get(0).selectedIndex;
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn