【js】鼠标点击空白处消失

时间:2022-07-13 10:22:33

var $ = function(i) {
    return document.getElementById(i)
};
function moreshow() {
    var e = $('pkCityBx');
    if (e.style.display != 'block') {
        e.style.display = 'block';
    } else {
        e.style.display = 'none';
    }
    return false
};
function moreddhide(e) {
    if (!e) var e = window.event;
    if (e.srcElement) {
        var a = e.srcElement.getAttribute("id")
    } else {
        var a = e.target.getAttribute("id")
    }
    if (a != "pkCity_Show") {
        $('pkCityBx').style.display = 'none'
    }
};
document.onclick = moreddhide;

 

HTML代码如下:

 

<a href="Javascript:void(0);" id="pkCity_Show" onclick="moreshow();">点击</a>
<div id="pkCityBx" style="display:none"> 内容文字... </div>