Home  >  Article  >  Web Front-end  >  Two ways to get the selected value of the select tag in js_javascript skills

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

WBOY
WBOYOriginal
2016-05-16 17:04:401152browse
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;
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