Dynamically create checkbox with JQuery from text input

后端 未结 3 598
执念已碎
执念已碎 2020-12-02 15:34

In my cms I have a checkbox group for categories. I would like to have a text input below that where the user can input the name of a new category and it will dynamically ad

3条回答
  •  情歌与酒
    2020-12-02 16:30

    One of the elements to consider as you design your interface is on what event (when A takes place, B happens...) does the new checkbox end up being added?

    Let's say there is a button next to the text box. When the button is clicked the value of the textbox is turned into a new checkbox. Our markup could resemble the following...

    Some label
    Some other label

    Based on this markup your jquery could bind to the click event of the button and manipulate the DOM.

    $('#addCheckbox').click(function() {
        var text = $('#newCheckText').val();
        $('#checkboxes').append(' ' + text + '
    '); });

提交回复
热议问题