我正在尝试使用jQuery创建一个可重用的函数,这将允许我在页面中使用多个引导程序警报,并通过cookie为每个函数保存状态。
HTML:
<p class="alert alert-box"> mytext message<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button></p>
JS:
jQuery(function( $ ){
// Check if the alert has been closed
if( $.cookie('alert-box') === 'closed' ){
$('.alert').hide();
}
// lets do the code binding here
// Grab your button
$('.close').click(function( e ){
// Do not perform default action when button is clicked
e.preventDefault();
/* If you just want the cookie for a session don't provide an expires
Set the path as root, so the cookie will be valid across the whole site */
$.cookie('alert-box', 'closed', { path: '/' });
});
});
我猜我需要使用
$this
但我不知道如何实现它。