Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用element.style添加到以前的样式_Javascript_Css - Fatal编程技术网

Javascript 使用element.style添加到以前的样式

Javascript 使用element.style添加到以前的样式,javascript,css,Javascript,Css,我有一个具有设置样式的html元素 element.style { "existing css;" } 我想在不覆盖“现有css”的情况下添加样式。(例如,我的风格是不透明度和指针事件) 我想要的结果是: element.style { existing css; opacity: 0; pointer-events: none; } 电流输出: element.style { opacity: 0; pointer-events: none; } 我知道我

我有一个具有设置样式的html元素

element.style {
  "existing css;"
}
我想在不覆盖“现有css”的情况下添加样式。(例如,我的风格是不透明度和指针事件)

我想要的结果是:

element.style {
  existing css;
  opacity: 0;
  pointer-events: none;
}
电流输出:

element.style {
  opacity: 0;
  pointer-events: none;
}    

我知道我可以添加一个类,但我想知道是否有一种方法可以使用javascriptselement.style=“css”。我也尝试过:

element.style += "opacity: 0; pointer-events: none;

任何反馈都将非常感谢。

“我知道我可以添加一个类,但是想知道是否有一种方法来使用JavaScript Epth.Cype = CSS”,请考虑解释一下你做了什么以及为什么要这么做。仅仅给出一个代码片段并没有多大帮助。
var d = document.getElementById("div1");
d.className += " otherclass";
var d = document.getElementById("div1");
d.className += " otherclass";
document.getElementById("div1").className += "otherclass";