javascript - 如果某个元素不可见,点击事件会触发吗? [英] javascript - does a click event fire on an element if it's not visible?
问题描述
如果您更改元素 visibility:hidden
的可见性,点击事件仍会触发,如果用户点击它?
我想隐藏一个元素(即<$ c $ c>< span> )并禁用点击事件触发,但保持位置在正常流文档。所以 display:none;
将无法工作,因为它从正常流程中删除文档,但想知道什么是我的其他选项通过CSS,而不实际处理点击事件和使用
JS
$ .click(function(){
alert('');
});
CSS
div {
background-color:red;
width:100px;
height:100px;
}
.hidden {
visibility:hidden
}
If you change the visibility of an element visibility: hidden
, will a click event still fire if the user clicks it?
I want to "hide" an element (i.e. <span>
) and disable the click event from firing, but retain is position in the normal flow of the document. So display: none;
won't work since it removes the document from the normal flow, but was wondering what are my other options via CSS without actually handling the click event and using preventDefault()?
No it won't fire when visibility:hidden
, here is proof :)
JS
$('div').click(function() {
alert('');
});
CSS
div {
background-color:red;
width:100px;
height:100px;
}
.hidden {
visibility:hidden
}
这篇关于javascript - 如果某个元素不可见,点击事件会触发吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!