如何禁用在div中单击 [英] How to disable clicking inside div

查看:105
本文介绍了如何禁用在div中单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于多种原因,我需要禁用点击 div 元素中的某些内容。例如,由于点击广告攻击。
我仍​​然希望它可见。

For many reasons I need to disable clicking on certain content within a div element. Due to clicking ads attacks, for example. I still want it to be visible tho.

考虑以下片段: -

Consider the following snippet :-

<div class="ads">
something should be here, i do not want to be clicked
</div>

如何禁用左键单击 div

推荐答案

可以使用的CSS属性是:

The CSS property that can be used is:

pointer-events:none

!重要
请注意,Opera Mini和IE 10及以下版本(包括)不支持此属性。这些浏览器需要另一种解决方案。

!IMPORTANT Keep in mind that this property is not supported by Opera Mini and IE 10 and below (inclusive). Another solution is needed for these browsers.

jQuery METHOD
如果要通过脚本而不是CSS属性禁用它们,这些可以帮助你:
如果你正在使用jQuery版本1.4.3 +:

jQuery METHOD If you want to disable it via script and not CSS property, these can help you out: If you're using jQuery versions 1.4.3+:

$('selector').click(false);

如果不是:

$('selector').click(function(){return false;});




  • 引用自:
    jquery - 禁用点击

    • Referenced from : jquery - disable click
    • 这篇关于如何禁用在div中单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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