Create

前端 未结 1 921
慢半拍i
慢半拍i 2021-01-21 11:53

I\'d like to build s on the fly in a box based on an AJAX response; i.e. if the responseText is 3, I\'d like to build 3 options:

相关标签:
1条回答
  • 2021-01-21 12:27

    You can do:

    var routeSelect = $("#PAG_POSITION").get(0);
    
    routeSelect.html(''); //clear-out options
    
    if (isNaN(opts) || opts == 0) {
        //Handles case where your response is invalid or zero
        routeSelect.append($('<option/>').val(0).html(0));
    } else {
        //Add n items to the dropdown
        for(var i = 0; i < opts; ++i) {
            routeSelect.append($('<option/>').val(i).html(i));
        }
    }
    

    Hope this helps.

    0 讨论(0)
提交回复
热议问题