CSS类无法动态添加选择框

时间:2015-09-11 05:40:30

标签: javascript jquery css

我正在通过jQuery动态添加按钮onclick上的选择框。但是选择框的CSS类不起作用。

这是我的代码:

$(document).ready(function () {

    var max_fields = 10; //maximum input boxes allowed
    var wrapper = $(".input_fields_wrap"); //Fields wrapper
    var add_button = $(".add_field_button"); //Add button ID
    var x = 1;
    $("#addMore").click(function (e) {
        $(".selectized").addClass("data-md-selectize data-md-selectize-bottom");
        e.preventDefault();
        if (x < max_fields) { //max input box allowed
            x++; //text box increment
            $(".more_field").append('<div class="uk-width-large-1-4 uk-width-medium-1-2 abc"  data-uk-grid-margin><div>Railway Station(s)</div><div> </div><select id="select_demo_2" class="selectized" data-md-selectize data-md-selectize-bottom><option value="a">Ambikapur</option><option value="b">Baloda Bazar</option><option value="c">Bhatapara</option><option value="d">Bilaspur</option><option value="e">Champa</option><option value="f">Dalli-Rajhara</option><option value="g">Dhamtari</option><option value="h">Dongargarh</option><option value="i">Durg-Bhilainagar</option><option value="j">Jagdalpur</option></select></div><div class="uk-width-large-1-4 uk-width-medium-1-2"><div>&nbsp; </div><div> &nbsp;</div><select id="select_demo_3" class="selectized" data-md-selectize data-md-selectize-bottom><option value="">Select...</option><option value="a">Agra Cantt. Railway Station (AGC)</option><option value="b">Agra Fort Railway Station (AF)</option></select></div><div class="uk-width-large-1-4 uk-width-medium-1-2"><div> &nbsp;</div><input type="text" class="md-input validate[required]" name="student_username" id="ereq1" placeholder="Distance"/></div><div class="uk-width-large-1-4 uk-width-medium-1-2"><div><div class="uk-form-row"></div></div></div><a href="#" onclick="calcTotal()" class="remove_field uk-icon-remove"></a></div>');
        }
        $(".more_field").on("click", ".remove_field", function (e) { //user click on remove text
            //alert('test');
            $(this).parent('.abc').remove();
            x--;
        })
    });
});

0 个答案:

没有答案