Javascript Get Values from Multiple Select Option Box

前端 未结 4 745
我寻月下人不归
我寻月下人不归 2020-11-29 08:38

This one is driving me nuts. It’s got to be something simple and stupid that I am overlooking. I have a multiple select box in a form. I am just trying to get the values th

4条回答
  •  野性不改
    2020-11-29 08:50

    Take a look at HTMLSelectElement.selectedOptions.

    HTML

    
    

    JavaScript

    var elem = document.querySelector("select");
    
    console.log(elem.selectedOptions);
    //=> HTMLCollection [, ]
    

    This would also work on non-multiple

    提交评论

提交回复
热议问题