Jquery to get the id of selected value from dropdown

前端 未结 4 1366
栀梦
栀梦 2021-02-10 14:32

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:15

    First set a custom attribute into your option for example nameid (you can set non-standardized attribute of an HTML element, it's allowed):

    ''
    

    then you can easily get attribute value using jquery .attr() :

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

    For Example:

        
    

    Jquery:

    function GetNameId(){
       alert($('#jobSel option:selected').attr("nameid"));
    }
    

提交回复
热议问题