-1

如何将 windows.getComputed 样式作为 int 值?

默认显示方式是字符串:

var style = window.getComputedStyle(elem1, null);
alert(style.top); //Returns a string
4

2 回答 2

1

parseFloat将为您提供实际值作为保留小数位的数字:

parseFloat(style.top);
于 2013-10-28T10:11:42.817 回答
1

parseInt() will return you the String as an Integer, so your code should look somehow like this:

var style = window.getComputedStyle(elem1, null);
alert(parseInt(style.top));
于 2013-10-28T10:01:07.543 回答