这是示例代码。我想禁用搜索 id 之外的点击。就像我们需要在弹出窗口中禁用外部点击
<body>
You can search <a href="google.com">here</a>
<div id="search">
Search
<input type="text" name=search><button>search</button>
</div>
</body>
最佳答案
您可以创建一个横跨整个屏幕的具有固定位置的 div,并将您希望能够点击的内容放在其中,使该元素之外的所有点击实际上都在该“空”div 上。
.disable-outside-clicks {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 10000;
}
.enabled-clicks {
width: 200px;
margin: 0 auto;
}
<div>
<button>This button will not work</button>
</div>
<div class="disable-outside-clicks">
<div class="enabled-clicks">
<button>This button will work</button>
</div>
</div>
关于javascript - 如何禁用特定div之外的点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44152202/