Converting a text input to a select element with JavaScript

前端 未结 4 1193
梦如初夏
梦如初夏 2020-12-18 22:41

I\'m doing some front end development on a hosted e-commerce platform. The system sends a text input for the customer to choose the quantity of items they want to add to the

4条回答
  •  太阳男子
    2020-12-18 22:54

    If you already have an dropdown/select list and you just want to add an item to it from a label/textbox then you can try this :

     if ($(textBoxID).val() != '') {
                    $(dropDownID)
                        .append($("")
                            .attr('value', ($(textBoxID).val()))
                                .text($(textBoxID).val())).val($(textBoxID).val())
    }
    

提交回复
热议问题