为什么这个脚本不起作用?
<!DOCTYPE html>
<html>
<head>
<title>Hello StackOverflow!</title>
</head>
<body>
<div id="testing">
<p>Bladybla</p>
</div>
<script>
var one = window.innerWidth;
var two = 5;
var three = one / two;
var four = '"' + Math.round(three) + "px" + '"';
document.getElementById("testing").style.marginTop = four;
</script>
</body>
</html>
当我在两者之间放置警报时var four
,它document.getElementById
会计算正确的值。问题出在.style.marginTop =
. 它不打印计算值。为什么?
在此先感谢,Jaapyse!