Home  >  Article  >  Web Front-end  >  获取select元素被选中的文本内容的js代码_javascript技巧

获取select元素被选中的文本内容的js代码_javascript技巧

WBOY
WBOYOriginal
2016-05-16 17:01:411301browse
复制代码 代码如下:

var sel=document.getElementById(id);//select元素的id
var index=sel.selectedIndex;//获取被选中的option的索引
var textsel= sel.options[index].text;//获取相应的option的内容
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