我遇到了Jquery .on()函数和Handlebars模板的问题。我wroted把手模板,动态添加他在文件:jquery点击事件不会与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>
所以我wroted点击该按钮处理程序:
$('.service').on('click', '.delete-service', function (e) {
alert('Clicked');
//$(this).parent().parent().remove();
});
当我添加这个模板文件,点击事件不会触发。问题是什么?
$('.service-wrapper').on(...);
不,不行。 – illatif
_doesn't work_ ....没有解释这个问题,你可以详细说明一下。目前的问题是什么?你在控制台中看到任何错误吗? – Jai
没什么。没有错误,当我点击动态添加按钮时没有任何操作。但按钮,在服务器(而不是动态)行动(警报)渲染的东西很好。 – illatif