javascript - 如果某个元素不可见,点击事件会触发吗? [英] javascript - does a click event fire on an element if it's not visible?

查看:579
本文介绍了javascript - 如果某个元素不可见,点击事件会触发吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您更改元素 visibility:hidden 的可见性,点击事件仍会触发,如果用户点击它?



我想隐藏一个元素(即<$​​ c $ c>< span> )并禁用点击事件触发,但保持位置在正常流文档。所以 display:none; 将无法工作,因为它从正常流程中删除文档,但想知道什么是我的其他选项通过CSS,而不实际处理点击事件和使用

c>,这里是证明:)



jsFiddle



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 :)

jsFiddle

JS

$('div').click(function() {
    alert('');
});

CSS

div {
    background-color:red;
    width:100px;
    height:100px;
}

.hidden {
    visibility:hidden
}

这篇关于javascript - 如果某个元素不可见,点击事件会触发吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆