ajax刷新后bootstrap css无法正常工作

时间:2015-06-15 08:18:11

标签: twitter-bootstrap bootstrap-switch

我正在使用Bootstrap进行开/关切换开​​关。在此页面中,它每5秒刷新一次ajax以重新加载页面内容。我面临的问题是当页面刷新ajax时,bootstrap-switch失去了它的css样式。

我使用firefox inspect,这就是我所看到的:

在ajax刷新之前

<div id="override">
.....
    <div class="margin-bottom-10">  <label for="option1"></label>  <div class="bootstrap-switch bootstrap-switch-wrapper bootstrap-switch-on bootstrap-switch-small bootstrap-switch-animate bootstrap-switch-id-1234>
                <div class="botstrap-switch-container">
                  <span class="bootstrap-switch-handle-on bootstrap-switch-primary">On</span>
                  <label class="bootstrap-switch-label" for="1234"></label>
                  <span class="bootstrap-switch-handle-off bootstrap-switch-default">Off</span>
                  <input id="1234" name="radio1" class="make-switch" data-size="small" checked="" type="checkbox">
        </div>
        </div>
        </div>
......
</div>

ajax刷新后:

    <div id="override">
    .....
        <div class="margin-bottom-10">  
          <label for="option1"></label>
          <input id="1234" name="radio1" class="make-switch" data-size="small" checked="" type="checkbox">
        </div>
..........
    </div>

ajax代码:

$.get(url, function(data) {
  $("#override").html(data);
}

如何重新加载那些必要的bootstrap css&amp;也许甚至是js ??

1 个答案:

答案 0 :(得分:0)

我假设您使用的是this

如果是,您可以执行类似

的操作
$.get(url, function(data) {
 $("#override").html(data);
 $(".make-switch").bootstrapSwitch(); //code to init the switch again
}