【发布时间】:2014-04-15 00:19:45
【问题描述】:
我创建了一个 JQuery 灯箱,它只在灯箱内的浏览器中心显示一个 div。
我希望在用户单击灯箱周围的透明背景时将其删除。
但是,当 div 也被单击时,它也会被删除。
http://michaeloneill.ie/cs230/lightbox/lighbox.html
jQuery
$(document).ready(function($) {
//click on the button
$('.viewCart').click(function() {
//markup for the lightbox
var lightbox = '<div id="lightbox">'+
'<div id="lightboxContent">'+
'<h3>Your Cart</h3>'+
'</div>'+
'</div>';
//append the lightobx
$('body').append(lightbox);
});
//remove the lightbox
$('#lightbox').live('click', function() { //use live because lightbox can be added and removed dynamically
$('#lightbox').remove();
});
});
【问题讨论】:
标签: javascript jquery lightbox