[英]Escaping hyphen on javascript's getElementbyId
I want to pass -webkit-background-clip property with javascript. 我想使用JavaScript传递-webkit-background-clip属性。
Because of the hyphen at start, I cant seem to get it right. 由于开始时有连字符,我似乎无法正确处理。 Tried it with [, ", ' etc. How do I escape dash?
尝试过[,“,'等。如何逃脱破折号?
document.getElementById("menu").style.-webkit-background-clip = "text";
You can use bracket notation... 您可以使用括号符号...
document.getElementById("menu").style["-webkit-background-clip"]
...or use camel case... ...或使用骆驼保护套...
document.getElementById("menu").style.webkitBackgroundClip
Note that JavaScript resolves these to different names, but the browser supports both. 请注意,JavaScript将这些名称解析为不同的名称,但浏览器同时支持这两种名称。
尝试document.getElementById("menu").style["-webkit-background-clip"] = "text";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.