在javascript中使用DOM设置文本阴影属性的值

时间:2015-05-15 09:25:04

标签: javascript css dom

我想在javascript中使用DOM逐个给出text-shadow属性的值。 text-shadow:h-shadow v-shadow blur-radius color | none | initial | inherit;

if(conf.hasOwnProperty('vshadow')) document.getElementById('p1').style.text.hshadow = 5px;
if(conf.hasOwnProperty('hshadow')) document.getElementById('p1').style.text.vshadow = 5px;
if(conf.hasOwnProperty('blurRadius')) document.getElementById('p1').style.text.blurradius = 5px;
if(conf.hasOwnProperty('shadowColor')) document.getElementById('p1').style.text.color = red;

我尝试了上面的代码。但这不起作用。 有没有办法在javascript中使用DOM

2 个答案:

答案 0 :(得分:1)

我不知道DOM对象 hshadow,vshadow,blurradius 是否真的存在,但正确的代码应该是document.getElementById('p').style.textShadow = "5px 5px 5px red"

答案 1 :(得分:0)

文本阴影语法为:

text-shadow: h-shadow v-shadow blur-radius color|none|initial|inherit;

因此,当您想要应用特定属性时,可以应用如下:

text-shadow: 2px 2px 2px #ff0000;

通过JS申请:

document.getElementById('p1').style.textShadow = "2px 2px 2px #ff0000";

希望这有帮助。