我收到错误消息“无法读取null的样式'style'”,我尝试了将脚本放在HTML底部的所有操作,但仍然出现错误。我该怎么办?
错误行:
document.getElementById("span").style.webkitTransform = v
"rotate"+p+"("+ps.value+"deg)"
function r(p) {
var ps;
ps = document.getElementById(p);
document.getElementById("span").style.webkitTransform = "rotate" + p + "(" + ps.value + "deg)"
}
<div class="box">
<div class="div">
<span class="span"></span>
</div>
</div>
X:<input type="range" id="X" onchange="r('X');" value="45" /> Y:
<input type="range" id="Y" onchange="r('Y')" /> Z:
<input type="range" id="Z" onchange="r('Z')" />
答案 0 :(得分:0)
How can I use CSS3 transform on a span?
function r(p) {
var ps;
ps = document.getElementById(p);
var rot = "rotate" + p + "(" + ps.value + "deg)";
console.log(rot);
document.querySelector(".div").style.webkitTransform = rot;
}
<div class="box">
<div class="div">
<span class="span">shfasjdfhalsdjfh</span>
</div>
</div>
X:<input type="range" id="X" onchange="r('X');" value="45" /> Y:
<input type="range" id="Y" onchange="r('Y')" /> Z:
<input type="range" id="Z" onchange="r('Z')" />