Get selected value of a dropdown's item using jQuery

后端 未结 30 1591
广开言路
广开言路 2020-11-22 06:48

How can I get the selected value of a dropdown box using jQuery?
I tried using

var value = $(\'#dropDownId\').val();

and



        
30条回答
  •  鱼传尺愫
    2020-11-22 07:13

    To get the jquery value from drop down you just use below function just sent id and get the selected value:

    function getValue(id){
        var value = "";
        if($('#'+id)[0]!=undefined && $('#'+id)[0]!=null){
            for(var i=0;i<$('#'+id)[0].length;i++){
                if($('#'+id)[0][i].selected == true){
                    if(value != ""){
                        value = value + ", ";
                    }
                    value = value + $('#'+id)[0][i].innerText;
                }
            }
        }
        return value;
    }
    

提交回复
热议问题