如何为此弹出窗口添加“关闭”按钮?单击Продолжить покупки时关闭。
HTML代码:
<div id="notification"></div>函数调用后的html代码
<div id="notification"><div class="layer"> </div><div class="addtocart_window"><div class="c"><div class="t">Товар добавлен в корзину</div><a class="btn btn-default btn-subscribe" href="/cart_items/" title="Оформить заказ">Оформить заказ</a><br><br><a class="t2 close2">Продолжить покупки</a></div></div></div>不管用。
$('#button-cart').bind('click', function() {
$.ajax({
url: 'index.php?route=checkout/cart/add',
type: 'post',
data: $('.product-info input[type=\'text\'], .product-info input[type=\'hidden\'], .product-info input[type=\'radio\']:checked, .product-info input[type=\'checkbox\']:checked, .product-info select, .product-info textarea'),
dataType: 'json',
success: function(json) {
$('.success, .warning, .attention, information, .error').remove();
if (json['error']) {
if (json['error']['option']) {
for (i in json['error']['option']) {
$('#option-' + i).after('<span class="error">' + json['error']['option'][i] + '</span>');
}
}
}
if (json['success']) {
$('#notification').html('<div class="layer"> </div><div class="addtocart_window"><div class="c"><div class="t">Товар добавлен в корзину</div><a class="btn btn-default btn-subscribe" href="/cart_items/" title="Оформить заказ">Оформить заказ</a><br><br><a class="t2 close2">Продолжить покупки</span></div></div>');
$('.success').fadeIn('slow');
$('html, body').animate({ scrollTop: 0 }, 'slow');
}
}
});
$('.close2').on('click', function(){
$('#notification').hide().empty();
});
});发布于 2014-01-27 07:42:40
可以将事件委托给最近的静态父级或$(document)。
$('#notification').on('click', '.close2', function(){
$(this).closest('#notification').empty().hide();
});您也可以将事件委托给这个$(document).on('click',。
发布于 2014-01-27 07:25:08
这取决于您所说的“关闭”指的是什么--我认为您要做的是隐藏通知,但也要空它,因为您已经在响应中添加了html内联。我看不到#notification上的css,但我假设这将首先隐藏通知窗口(假设模式就是这样),然后空出它的内容。
$('.close2').on('click', function(){
$('#notification').hide().empty();
});https://stackoverflow.com/questions/21375022
复制相似问题