无法通过 JS 或 jQuery 设置规则“指针事件”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15295393/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 14:45:25  来源:igfitidea点击:

Impossible to set the rule "pointer-events" through JS or jQuery?

javascriptjquerycss

提问by Sonia

I've to manipulate the interaction with an element in runtime, making it invisible and "no interactible".. The rule that can accomplish the second, is "pointer-events: none"

我必须在运行时操纵与元素的交互,使其不可见且“不可交互”.. 可以完成第二个的规则是“指针事件:无”

The problem is that it doesn't recognized from JS or jQuery... why?

问题是它无法从 JS 或 jQuery 中识别出来……为什么?

回答by jAndy

I don't think I understand the question, but (using jQuery)

我不认为我理解这个问题,但是(使用 jQuery)

$( document.body ).css( 'pointer-events', 'none' );

will work just fine for supporting browsers (ignoring any pointer event). However, if you remove / hidethe element, pointer events will of course also no longer work if you hide it by

将适用于支持浏览器(忽略任何指针事件)。但是,如果您删除/隐藏元素,如果您通过以下方式隐藏它,指针事件当然也将不再起作用

display: none

回答by frodo2975

You can use the css pointer-events: none;to allow events to go through. Also, like 1j01 commented, jquery will accept camelCase to get around the problem of dashes in the name:

您可以使用 csspointer-events: none;来允许事件通过。另外,就像 1j01 评论的那样,jquery 将接受驼峰命名来解决名称中的破折号问题:

$('.my-class').css({pointerEvents: "none"})