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

jQuery or Js gets the selected value or text

巴扎黑
Release: 2016-11-25 14:04:27
Original
1649 people have browsed it

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;

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template