Get drop down value

后端 未结 5 739
时光取名叫无心
时光取名叫无心 2020-12-01 14:08

How to determine what is selected in the drop down? In Javascript.

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-01 15:06

    If your dropdown is something like this:

    
    

    Then you would use something like:

    var a = document.getElementById("thedropdown");
    alert(a.options[a.selectedIndex].value);
    

    But a library like jQuery simplifies things:

    alert($('#thedropdown').val());
    

提交回复
热议问题