我在 handlebars 模板中有一个 bootstrap
切换,虽然页面加载时间完美它是可见的,但是在重新模板化 handlebars 模板(哪个模板有切换)之后它不可见。
重新模板化之前:
代码:
<div class="switch switch-square has-switch" data-on-label="<i class='fui-check'></i>" data-off-label="<i class='fui-cross'></i>"><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"> </label><span class="switch-right"><i class="fui-cross"></i></span></div></div>
重新模板后:
重新模板代码后:
<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>
句柄代码:
<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"> </label><span class="switch-right">1</span></div><span class="switch-left">2</span><label for="qtenToggle"> </label><span class="switch-right">1</span></div><span class="switch-left">2</span><label for="qtenToggle"> </label><span class="switch-right">1</span></div><span class="switch-left">2</span><label for="qtenToggle"> </label><span class="switch-right">1</span></div><span class="switch-left">2</span><label for="qtenToggle"> </label><span class="switch-right">1</span></div><span class="switch-left">2</span><label for="qtenToggle"> </label><span class="switch-right">1</span></div><span class="switch-left">2</span><label for="qtenToggle"> </label><span class="switch-right">1</span></div></div>
Bootstrap 函数:
$('.switch')['bootstrapSwitch']();
关于javascript - 我如何渲染 Bootstrap 切换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20787528/