【发布时间】:2023-04-02 05:31:01
【问题描述】:
我有几个 .handlebars 模板加载到车把默认布局中,使用车把作为 node.js 的视图引擎
模板使用 {{{ body }}} html 转义加载到 body 标记中:
<body>
{{{ body }}}
</body>
当涉及模板中的 div 时..为什么 jQuery 显示/隐藏效果会这样工作:
<label class="btn">
<input type="checkbox" id="theBtn"> theBtn
</label>
..a bunch of html..
<div class="theDiv" style="display:none;"></div>
$(document).ready(function () {
$("#theBtn").change(function() {
$(".theDiv").slideToggle();
});
});
但这种方式只有在 HTML 直接以默认布局而不是模板编写时才有效:
.hide {
display: none;
}
<label class="btn">
<input type="checkbox" id="theBtn"> theBtn
</label>
..a bunch of html..
<div class="theDiv hide"></div>
$(document).ready(function () {
$("#theBtn").on('click', function () {
var $when = $(".theDiv");
$when.slideToggle();
$(".theDiv").not($when).slideUp();
});
});
【问题讨论】:
标签: javascript jquery html css handlebars.js