How to add Drop-Down list (<select>) programmatically?

前端 未结 9 2220
北恋
北恋 2020-11-27 14:12

I want to create a function in order to programmatically add some elements on a page.

Lets say I want to add a drop-down list with four options:

<         


        
9条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-27 14:28

    Here's an ES6 version, conversion to vanilla JS shouldn't be too hard but I already have jQuery anyways:

    function select(options, selected) {
      return Object.entries(options).reduce((r, [k, v]) => r.append($('
    提交评论

提交回复
热议问题