[Vuejs]-Multiple of the similar "Select Option" ID , Dynamic Javascript Code

0👍

Since id can not be the same, you can define a global variable like index to memo the count as part of id;

Like to dynamically add select with id “select-repo”+index; e.g. select-repo1, select-repo999

Here’s an example:

var index = 1;

function addSelect(){
    $('#somewhere').append('<select id="select-repo'+index+'">');
    $('select-rep'+index).selectize(){
        ....
    };
    index++;
}

And you can easily get the select index by parse Id string.

Leave a comment