Get inner html of the selected option

前端 未结 5 1338
深忆病人
深忆病人 2020-12-15 21:30

I have something like this:

select = document.getElementById(\"select\");
select.onchange = function(){
  alert(this.value); //returns the selected value
  a         


        
5条回答
  •  -上瘾入骨i
    2020-12-15 22:14

    This will work.

    select = document.getElementById("select");
    select.onchange = function(){
        alert(this.value); //returns the selected value
        alert(this.innerHTML); //returns the entire select with all the options
        var options = this.getElementsByTagName("option");
        var optionHTML = options[this.selectedIndex].innerHTML;  
        alert(optionHTML); //this is what I want, but it works now
    };
    

提交回复
热议问题