为了使div
元素在您单击它们时自毁,您可以执行以下操作:
// Inside the #container, when somebody clicks a div
$("#container").on("click", "div", function(){
// Remove that div
$(this).remove();
});
至于切换每组可见性的复选框:
// When somebody clicks on a checkbox
$(":checkbox").on("click", function(){
// Reference for the checkbox, its name, and checked property (true|false)
var chbx = $(this),
name = chbx.attr("name"),
show = chbx.prop("checked");
// Find elements whose id begins with the checkbox name
// and set their toggle to true or false
$("[id^=" + name + "]").toggle( show );
});
在这里查看它的实际效果:http: //jsfiddle.net/6GBpW/3/