Bootstrap Popover + Meteor JS点击事件
Bootstrap Popover + Meteor JS click event
我试图通过点击引导弹出窗口内的按钮来触发流星事件。但是,事件没有被触发。
下面是我的代码: <button name="newLetter" class="glyphicon glyphicon-plus newLetter" type="button" data-container="body" data-toggle="popover" data-placement="right"></button>
<div id="popover-content" class="hide">
<textarea></textarea>
<button class='glyphicon glyphicon-ok btn btn-success btn-xs addNewLetter'></button>
</div>
Template.templateName.events({
'click .newLetter': function(e, t) {
$(".newLetter").popover({
html: true,
title: 'New Letter',
content: function() {
return $("#popover-content").html();
}
});
},
'click .addNewLetter': function(e, t) {
console.log('test');
}
});
首先使用您的代码,这不会在第一次单击时显示弹出窗口。你应该做的:
Template.templateName.rendered = function() {
$(".newLetter").popover({
html: true,
title: 'New Letter',
content: function() {
return $("#popover-content").html();
}
});
}
如果你检查你的调试器,你会看到,每次你点击。newletter按钮,bootstrap取#popover-content的内容,并把它放在一个新的div类。popover。如果您想了解如何在动态创建的元素上绑定事件,您应该检查这个答案。(解决方案是使用on()
)
现在,对于正在发生的事情,流星绑定了一个点击事件在#popover-content中的。addnewletter,而不是在div.popover中动态创建的元素。addnewletter,这就是为什么它不工作。我找到了一个变通方法:
Template.templateName.rendered = function() {
$(document).on('click', '.addNewLetter', function() {
console.log('hey');
});
}
相关文章:
- 为什么js事件消失了
- 为什么我的点击事件没有使用 react js 触发
- node.js请求数据事件未在CORS ajax调用中触发
- 在D3.js中,有没有任何方法可以将x和y方向上的滚动事件绑定到平移svg
- 使用onkeyup JS事件检查输入的值是否唯一
- dropdown.js中的复杂事件处理
- 使用Bacon.js发出事件
- 针对重复发生的事件,使用moment.js防止DST偏移
- d3 中是否有点击和双击事件.js力定向图
- gulpfile 引发错误事件.js:154
- Chrome 扩展程序在后台注册事件.js
- Google Analytics(分析)在淘汰赛中推送跟踪事件.js数据绑定
- 如何在木偶中使用模型事件.js
- 节点.js - 事件.js:154 抛出错误写入 EPIPE;程序崩溃
- 侦听单击事件 JS
- 使客户端在选项卡关闭节点上发送断开连接事件.js
- 如何在onkepress事件+ JS上计算sub_total和total_price输入
- 不能在onclick事件(JS)上向元素插入函数
- 附加一个错误事件js/jquery
- 捕获鼠标拖动事件JS时会发生奇怪的事情