Home > Web Front-end > JS Tutorial > body text

Two ways to get the selected value of the select tag in js_javascript skills

WBOY
Release: 2016-05-16 17:04:40
Original
1151 people have browsed it
Copy code The code is as follows:

var obj = document.getElementByIdx_x("testSelect"); //Positioning idvar index = obj.selectedIndex; // The selected index var text = obj.options[index].text; // The selected text var value = obj.options[index].value; // The selected value is obtained from jQuery. One way$('#testSelect option:selected').text();//Selected text$('#testSelect option:selected') .val();//Selected value$("#testSelect ") .get(0).selectedIndex;//Second indexing method $("#tesetSelect").find("option:selected").text();//Selected text....val();... .get(0).selectedIndex;
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!