当用户在DIV之外单击时,如何使用JavaScript隐藏DIV?
要在用户单击div时隐藏div,请尝试运行以下代码
示例
<!DOCTYPE html>
<html>
<body>
<script>
window.onload = function(){
var hideMe = document.getElementById('hideMe');
document.onclick = function(e){
if(e.target.id !== 'hideMe'){
hideMe.style.display = 'none';
}
};
};
</script>
<div id="hideMe">Click outside this div and hide it.</div>
</body>
</html>热门推荐
10 生日油画棒祝福语简短
11 同事们生日祝福语简短
12 收围巾的祝福语简短
13 送师姐的祝福语简短
14 升职祝福语朋友简短精辟
15 高温早安祝福语简短精辟
16 甄嬛传祝福语简短
17 对学姐的简短祝福语
18 宝宝100日简短祝福语