js 冒泡事件 点击任意地方隐藏元素

时间:2020-12-10 23:15:12
   $(function () {
$("#but").click(function (e) {//
$("#UL").show();//显示速度
/*阻止冒泡事件*/
e = window.event || e;
if (e.stopPropagation) {
e.stopPropagation();
} else {
e.cancelBubble = true;
} });
$("#UL").click(function (e) {
/*阻止冒泡事件*/
e = window.event || e;
if (e.stopPropagation) {
e.stopPropagation();
} else {
e.cancelBubble = true;
}
});
$(document).click(function () {
$("#UL").hide();//隐藏速度
});
)}
#but 点击显示的ID
#UL 点击隐藏的ID