javascript - 我如何渲染 Bootstrap 切换

标签 javascript jquery css templates twitter-bootstrap

我在 handlebars 模板中有一个 bootstrap 切换,虽然页面加载时间完美它是可见的,但是在重新模板化 handlebars 模板(哪个模板有切换)之后它不可见。

重新模板化之前:

Before Re-Template

代码:

 <div class="switch switch-square has-switch" data-on-label="&lt;i class='fui-check'&gt;&lt;/i&gt;" data-off-label="&lt;i class='fui-cross'&gt;&lt;/i&gt;"><div class="switch-animate switch-off"><input type="checkbox" id="colorBar-Toggle"><span class="switch-left"><i class="fui-check"></i></span><label for="colorBar-Toggle">&nbsp;</label><span class="switch-right"><i class="fui-cross"></i></span></div></div>

重新模板后:

enter image description here

重新模板代码后:

 <div class="switch switch-square" data-on-label="&lt;i class='fui-check'&gt;&lt;/i&gt;" data-off-label="&lt;i class='fui-cross'&gt;&lt;/i&gt;"><input type="checkbox" id="colorBar-Toggle"></div>

句柄代码:

      <script id="planner-template" type="text/x-handlebars-template">

    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="table table-bordered table-responsive" id="joy_fifth" data-intro="5. You are now ready to play   with the planner!" data-position="top">  
      <thead>
            <tr>    
                <th width="20%">Bizstep</td>
                <th width="20%">Location</td>
                <th width="15%">Time Duration</td>
                <th width="15%">Temperature</td>
                <th width="15%">Freshtime Points</td>
                <th width="15%"><div class="switch switch-square" data-on-label="<i class='fui-check'></i>" data-off-label="<i class='fui-cross'></i>"><input type="checkbox" id="colorBar-Toggle"/></div></td>
            </tr>
         </thead>
             <tbody>...</tbody>
      </script>

请任何人帮助我,这对我来说非常重要。

最佳答案

大家好,我在重新模板化后创建的,如果我调用以下函数,它工作正常。但是在调用函数后,其他切换也有效。我在 bootstrap-switch.js 文件中找到了以下函数。

我不知道为什么其他开关会起作用。在其他开关周围又添加了一个新的 div。因为我在主开关周围得到了额外的填充。

其他切换代码:

<div class="switch switch-square has-switch" data-on-label="2" data-off-label="1"><div class="switch-animate switch-off switch-on"><div class="switch-animate"><div class="switch-on switch-animate"><div class="switch-animate"><div class="switch-animate"><div class="switch-animate"><div class="switch-animate"><input type="checkbox" id="qtenToggle"><span class="switch-left">2</span><label for="qtenToggle">&nbsp;</label><span class="switch-right">1</span></div><span class="switch-left">2</span><label for="qtenToggle">&nbsp;</label><span class="switch-right">1</span></div><span class="switch-left">2</span><label for="qtenToggle">&nbsp;</label><span class="switch-right">1</span></div><span class="switch-left">2</span><label for="qtenToggle">&nbsp;</label><span class="switch-right">1</span></div><span class="switch-left">2</span><label for="qtenToggle">&nbsp;</label><span class="switch-right">1</span></div><span class="switch-left">2</span><label for="qtenToggle">&nbsp;</label><span class="switch-right">1</span></div><span class="switch-left">2</span><label for="qtenToggle">&nbsp;</label><span class="switch-right">1</span></div></div>

Bootstrap 函数:

 $('.switch')['bootstrapSwitch']();

关于javascript - 我如何渲染 Bootstrap 切换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20787528/

相关文章:

javascript - 使用 Google Closure 编译器防止将导出的属性内联为常量

javascript - 如何选择 DOM 中具有相同类的所有元素?

javascript - 解析js html库中的字符串(语言字符串)

html - 有没有办法让元素在不从流中移除的情况下被定位到右边?

javascript - 从 RequireJS 中的 CommonJS 样式模块导出构造函数

javascript - 按跨度类别对 div 进行排序

javascript - 需要一个接受任何包含至少 3 个字母的文本的正则表达式

javascript - 插入有序数组的计算效率最高的方法?

jquery - Bootstrap 4 - 需要折叠来调整砌体布局

Javascript 动画离开