【发布时间】:2014-03-20 22:24:09
【问题描述】:
我有问题
我用 Mustache.js 创建了一个模板(示例):
<script type="text/template" id="info">
<div id="info-content">
{{>photoEl}}
</div>
</script>
某些元素被创建并添加为部分(示例):
partials.photoEl = '<span class="photo"><a class="button" href="#"></a></span>';
但我无法使用 jQuery 定位任何元素。
$('.button').click(function(event){
console.log('click');
});
什么都不做……
知道为什么吗?
【问题讨论】:
-
为什么你的div在脚本标签o.o里面?如果您要添加处理程序,则该元素不在 DOM 中,您需要向 .button 添加一个委托事件,因为它是在 DOM 由 mustache 准备好之后创建的(如果已创建)。