Jquery to get the id of selected value from dropdown

前端 未结 4 1224
面向向阳花
面向向阳花 2021-02-10 14:26

I have a drop down list that fetches values from db as follows

$.get(\'/getJobs\', function (jobs) {
        seljobs = jobs;
        var i = 0;
        jobs.forE         


        
4条回答
  •  时光说笑
    2021-02-10 15:26

    If you are trying to get the id, then please update your code like

      html += '';
    

    To retrieve id,

    $('option:selected').attr("id")
    

    To retrieve Value

    $('option:selected').val()
    

    in Javascript

    var e = document.getElementById("jobSel");
    var job = e.options[e.selectedIndex].value;
    

提交回复
热议问题