JavaScript设置指针事件 [英] JavaScript setting pointer-events

查看:89
本文介绍了JavaScript设置指针事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过JavaScript为div设置 pointer-events:none ,但是该属性未被应用。

I am trying to set pointer-events: none for a div through JavaScript, however the property is not being applied.

我试过:

document.getElementById("div").setAttribute("pointer-events", "none");

并且:

document.getElementById("div").style.pointer-events = "none";

但是没有效果,任何想法?

推荐答案

您的第一次尝试失败,因为它是一个CSS属性而不是属性(样式的一部分属性)。

Your first attempt failed because it was a CSS property and not an attribute (part of the style attribute).

你的第二次尝试失败了,因为出于某些原因,当使这个API 套管式 - 这个被转换为 camelCasingLikeThis 。这可能是 ,因为构建JavaScript的人和构建CSS的人没有很好的协调。

Your second attempt failed because for some off reason, when making this API casing-like-this gets converted to camelCasingLikeThis . This is likely because the guys who built JavaScript and the guys who built CSS weren't very well coordinated.

以下应该有效:

document.getElementById("div").style.pointerEvents = "none";

这篇关于JavaScript设置指针事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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