【发布时间】:2017-08-25 16:35:13
【问题描述】:
我对 Jquery .on() 函数和 Handlebars 模板有疑问。我编写了 Handlebars 模板并在文档中动态添加:
$('.services-wrapper').append(serviceTemplate({index : ++maxIndex}));
这个模板有一个按钮:
<p>
<?= Html::buttonInput('Delete', [
'class' => 'btn btn-danger delete-service',
'id' => 'js-delete-service',
'data' => [
'index' => $index,
],
]) ?>
</p>
所以我在这个按钮上写了点击处理程序:
$('.service').on('click', '.delete-service', function (e) {
alert('Clicked');
//$(this).parent().parent().remove();
});
当我将此模板添加到文档时,单击事件不会触发。问题是什么?
【问题讨论】:
-
如果有效,请发布答案。我在使用带有把手的 mousemove 事件时遇到了类似的问题。
标签: javascript php jquery html frontend