Js gets the selected value of the select tag in two ways

  • 2020-03-30 01:17:22
  • OfStack

 
var obj = document.getElementByIdx_x( " testSelect " ); // positioning idvar index = obj.selectedIndex; //  Select the index var text = obj.options[index].text; //  Select the text var value = obj.options[index].value; //  The selected value jQuery Get selected in select Value the first way $('#testSelect option:selected').text();// Selected text $('#testSelect option:selected') .val();// The value of the selected $("#testSelect ").get(0).selectedIndex;// The index   The second way $("#tesetSelect").find("option:selected").text();// Selected text... .val(); ... .get(0).selectedIndex; 

Related articles: