Home > Web Front-end > JS Tutorial > A simple example of getting the value and text value of select (jquery and javascript)

A simple example of getting the value and text value of select (jquery and javascript)

高洛峰
Release: 2017-01-03 16:55:09
Original
1040 people have browsed it

1、jquery

//获取value值
$("#ddlSubmodel").val();
//获取text值
$("#ddlSubmodel").find("option:selected").text();
Copy after login

2、javascript

//获取value值
document.getElementById("ddlSubmodel").value;
//获取text值
var select = document.getElementById("ddlSubmodel");
if (select.selectedIndex > -1) {
  select.options[select.selectedIndex].innerText;
}
Copy after login

The above is this article I hope the content of this article can bring some help to everyone's study or work. If you have any questions, you can leave a message to communicate. I also hope to support the PHP Chinese website!

For more simple examples of obtaining the value and text value of select (jquery and javascript), please pay attention to the PHP Chinese website!


Related labels:
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
Latest Issues
AngularJS Select default value?
From 1970-01-01 08:00:00
0
0
0
Select option using PHP loop
From 1970-01-01 08:00:00
0
0
0
Chrome doesn't apply padding to select options
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template