【发布时间】:2013-06-15 22:53:57
【问题描述】:
我正在使用 Twitter Bootstrap 中的“警报”功能来显示用户通知,如下所示:
<div class="notification alert alert-info">
<button type="button" class="close" data-dismiss="alert">×</button>
My message goes here
</div>
这些通知在用户关闭它们之前一直存在,因此当用户单击“关闭”按钮时,我想向服务器发出一个 ajax 查询,指示应该永久关闭通知。
我正在使用 jQuery 的 on() 函数,如下所示:
$(document).on('click', '.notification .close', function (e) {
alert('hi!');
console.log(e);
e.preventDefault();
});
这很好用,但我想知道是否有“Bootstrappy”方式来做到这一点?
【问题讨论】:
-
我的第一印象是您的解决方案很好-但是-在回答之后-我认为您的问题是正确的。 “正确的方法”可能包括抽象/封装的附带好处 - 例如 - BootStrap 插件可以模拟移动设备的触摸事件,而 jQuery.on('click') 可能无法捕获。
标签: javascript ajax twitter-bootstrap notifications