由于许多原因,我需要禁用单击div元素中的某些内容.例如,由于点击广告攻击. 尽管如此,我还是希望它是可见的.

考虑下面的片段:

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

在那div个地方怎么才能停用左键点击的功能呢?

推荐答案

可以使用的CSS属性是:

pointer-events:none

!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 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);

If not:

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

你可以用101(Documentation)次点击re-enable

Note that pointer-events overrides the cursor property, so if you want the cursor to be something other than the standard cursor, your css should be place after pointer-events.

Jquery相关问答推荐

使用 howler.js 中的变量播放多种声音

Bootstrap 3模态框和video.js视频未正确调整大小

如果选中了三个sibling ,则选中一个复选框

如何使用 AJAX 和 jQuery 发布 django 表单

JQuery 数据 Select 器不使用 .data 更新

如何在循环内创建动态变量名称?

使用 jQuery 发送 JSON 数据

ajax调用后jQuery点击功能不起作用?

你如何获得文本区域中的光标位置?

如何在 jQuery .each() 的每次迭代之间添加暂停?

字符串化(转换为 JSON)具有循环引用的 JavaScript 对象

为什么不推荐$().ready(handler)?

如何将参数传递给 jQuery 中的事件处理程序?

jQuery位置href

使用 jQuery 在 Select 列表中隐藏选项

在 jquery 中使用 AJAX Post 从强类型 MVC3 视图传递模型的正确方法

jQuery .each() 索引?

jQuery:通过 .attr() 添加两个属性;方法

小于 10 给数字加 0

Twitter Bootstrap - 选项卡 - URL 不变