Home  >  Article  >  Web Front-end  >  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)

高洛峰
高洛峰Original
2017-01-03 16:55:09976browse

1、jquery

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

2、javascript

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

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!


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