Home  >  Article  >  Web Front-end  >  jQuery or Js gets the selected value or text

jQuery or Js gets the selected value or text

巴扎黑
巴扎黑Original
2016-11-25 14:04:271580browse

jquery
Get the text value $("#select1 option:selected").text();
Get the value $("#select1 option:selected").val();

js

var obj = document. getElementById(”selectId”); //Location id

var index = obj.selectedIndex; //Select the index
Get the text value
var text = obj.options[index].text; //Select the text
Get the value
var value = obj.options[index].value;

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