繁体   English   中英

Bootstrap Datepicker在使用JavaScript追加时不起作用

[英]Bootstrap Datepicker not working while append using javascript

我在追加到div的表单元素上使用引导日期选择器。 追加到div后不起作用。

$('#bp').on('click', function(){
    $('.wraper').empty();
           var data ='<form role="form" method="get" action="" class="has-validation-callback">'+
           '<h5 class="center" style="padding-right: 189px;">Serach Booking & Placement Report</h5><br>'+
           '<input type="hidden" name="type" id="type" class="col-xs-12 " value="bp" data-validation="required" placeholder="Range From" />'+



              '<div class="col-sm-4">\n'+
               '<label class="col-sm-4 control-label no-padding-right" for="unit">From </label>'+
               '<input type="text" name="range_from" id="range_from" class="datepicker col-xs-12 " value="" data-validation="required" placeholder="Range From" />'+
           '</div>'+
           '<div class="col-sm-4">'+
               '<label class="col-sm-4 control-label no-padding-right" for="unit">To </label>'+
               '<input type="text" name="range_to" id="range_to" class="datepicker col-xs-12 " value="" data-validation="required" placeholder="Range to" />'+
           '</div>'+

           '<div class="col-sm-2">'+
           '<label class="col-sm-2 control-label no-padding-right" for="unit">  </label>'+
               '<br><button type="submit" class="btn btn-primary btn-sm">'+
                                        '<i class="fa fa-search"></i>'+
                                        'Search'+
                                    '</button>'+
           '</div>'+
           '</form>';
           $('.order-wraper').append(data);
           $('.datepicker').datepicker();
        });

像这样初始化您的选择器

$('body').on('focus',".datepicker ", function(){
    $(this).datepicker();
});​

请参阅http://api.jquery.com/on/ ,尤其是有关“委托事件”的部分

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM