简体   繁体   English

通过Ajax注入Bootstrap组件

[英]Inject Bootstrap component via ajax

I've got a problem with injecting a Bootstrap component via ajax. 我通过ajax注入Bootstrap组件时遇到问题。 When I add eg a select, I use this line of code: 当我添加一个选择时,我使用以下代码行:

<select class="selectpicker" data-width="75%">

And a lot of HTML code is generated via javascript, see: http://silviomoreto.github.io/bootstrap-select/ 并且许多HTML代码是通过javascript生成的,请参见: http : //silviomoreto.github.io/bootstrap-select/

So, when I try to inject code eg after submitting a form: 因此,当我尝试注入代码(例如在提交表单之后)时:

    $('#xForm').submit(function(event) { 
       var _select = '<select class="selectpicker" data-width="75%">';
       $("#data").append(_select);
    });

The element will be added to DOM just like it is, without being transformed like the above. 元素将按原样添加到DOM,而无需像上面那样进行转换。 How can I re-call the function, that creates the whole code around the selectpicker after the page is loaded? 我如何调用该函数,该函数会在页面加载后围绕selectpicker创建整个代码?

I hope you know what I mean. 我希望你明白我的意思。

Thanks! 谢谢!

Btw: on jQueryMobile it would work with $(_select).appendTo("#data").trigger('create'); 顺便说一句:在jQueryMobile上,它可以与$(_ select).appendTo(“#data”)。trigger('create');一起使用; - on Bootstrap unfortunately not! -很遗憾,Bootstrap上没有!

Try 尝试

Enable Bootstrap-Select via JavaScript: $(el).selectpicker() 通过JavaScript启用Bootstrap-Select: $(el).selectpicker()

$('#xForm').submit(function (event) {
    var _select = '<select class="selectpicker" data-width="75%">';
    $(_select).selectpicker().appendTo("#data");
});

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

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