我想在样式对象中提交我自己的变量。我会告诉你我的意思:在js样式对象中设置自己的变量
var example = background
element.style.example // example is equal to the variable up top
有没有这样做?
我想在样式对象中提交我自己的变量。我会告诉你我的意思:在js样式对象中设置自己的变量
var example = background
element.style.example // example is equal to the variable up top
有没有这样做?
假设你要定义的属性来动态设置,你可以用下面的办法:
var example = 'background';
element.style[example] = 'black';
您可以使用括号记号
var example = "background";
element.style[example] = "#fff";
谢谢!这是一个快速的答案 –
谢谢你这个快速的答案,不知道这是可能的JS。我尝试过'style {example}'和'style(example)',但我需要'[]' –