2014-01-17 27 views
-1

我怎样才能让elem.setAttribute("style","border-top-right-radius: 5% 5%;"); 要发送这封elem.setAttribute("style","border-top-right-radius: 5% x%;");如何:setAttribute发送5%+ var x%?

SETT最后5%至变种x的值。

var element1 = document.getElementById("content"), 
style = window.getComputedStyle(element1), 
height = style.getPropertyValue('height'); 

var string1 = height; 
string1 = string1.replace(/\D/g,''); 

var x = string1/100 * 5; 
alert(string1); 
alert(x); 


var elem = document.getElementById("content"); 
elem.setAttribute("style","border-top-right-radius: 5% 5%;"); 

回答

0

你可以concetenate字符串:

elem.setAttribute("style","border-top-right-radius: 5% " + x + "%;"); 
+0

由于将作为SETT答案10分钟无法相信我忘了我可以使用+ +! – KevinHaugen

0

试试这个

var x = string1/100 * 5; 
elem.setAttribute('style','border-top-right-radius: 5%'+ x +'%;');