点击弹出一个窗口,再点击任意地方窗口关闭

时间:2022-09-19 23:40:07
$(function(){ $("#relateExplain").hide(); $("#dyExplain").hide(); $("#relateExplainBtn").click(function(){ if(window.event) event.cancelBubble = true;    else event.stopPropagation(); $("#relateExplain").css("position","absolute"); $("#relateExplain").css("top","75px"); $("#relateExplain").css("left","20px"); $("#dyExplain").hide(); $("#relateExplain").toggle(); });
$("#dyExplainBtn").click(function(){ if(window.event) event.cancelBubble = true;    else event.stopPropagation(); $("#dyExplain").css("position","absolute"); $("#dyExplain").css("top","185px"); $("#dyExplain").css("left","20px"); $("#relateExplain").hide(); $("#dyExplain").toggle(); }); } <%--点击任意地方关闭窗口--%> document.onclick = function(){$("#relateExplain").hide();$("#dyExplain").hide();}
还可以在body添加onclick事件,如doclose()方法 function doclose(){ $("#relateExplain").hide();  $("#dyExplain").hide(); }