How do I get the value of drop down list on page load

后端 未结 4 1268
星月不相逢
星月不相逢 2021-01-13 07:00

Using jQuery, how can I get the selected item\'s value in a select when the page loads? I can do it onChange etc but cant figure out the way on page load.

Here\'s my

4条回答
  •  情歌与酒
    2021-01-13 07:32

    The best solution and siple:

    $(document).ready(function() {
    $.fn.symbCost = function(pos) {
    var total = parseInt($(this).val().split('#')[pos]);
        return total;
    }   
    $("#symb").change(function() {
        var val = $(this).symbCost(0);
    }).triggerHandler('change');
    

    });

    Or this

    $(document).ready(function() {
    $.fn.symbCost = function(pos) {
        var total = parseInt($(this).val().split('#')[pos]);
        return total;
    }
    $("#symb").change(function() {
        var val = $(this).symbCost(0);
    }).symbCost(0);
    

    });

提交回复
热议问题