javascript change select option text

后端 未结 3 623
予麋鹿
予麋鹿 2021-01-11 09:40

Im trying to modify the text of the first select option via javascript. But it empties the entire select option

 
                        
    
提交评论

  • 2021-01-11 10:06

    I think this should work:

     <select name='stuff'>
              <option id="first" value="a"> Pepsi </option>
              <option value= "b"> Juice </option>
         </select>
    
    
        <script type="text/javascript">
            document.getElementById("first").innerHTML = "Water";
        </script>
    
    0 讨论(0)
  • 2021-01-11 10:08

    You can try this:

     $('select[name=stuff] option:first').html("abcd");
    
    0 讨论(0)
  • 提交回复
    热议问题