JQuery create new select option

前端 未结 6 1384
遥遥无期
遥遥无期 2020-12-29 19:46

I have the below functions in regular JavaScript creating select options. Is there a way I can do this with jQuery without having to use the form object? Perhaps storing the

6条回答
  •  没有蜡笔的小新
    2020-12-29 19:50

    Something like:

    function populate(selector) {
      $(selector)
        .append('')
        .append('')
    }
    
    populate('#myform .myselect');
    

    Or even:

    $.fn.populate = function() {
      $(this)
        .append('')
        .append('')
    }
    
    $('#myform .myselect').populate();
    

提交回复
热议问题