Javascript 如何确定此代码为何不输出任何内容?
我正在学习JavaScript动画。我写了这段代码,但它不起作用。我怎样才能找到问题?我想在单击按钮时移动蓝色方块:Javascript 如何确定此代码为何不输出任何内容?,javascript,debugging,animation,Javascript,Debugging,Animation,我正在学习JavaScript动画。我写了这段代码,但它不起作用。我怎样才能找到问题?我想在单击按钮时移动蓝色方块: <html> <!-- css code --> <style> body{background-color:black;} #a{ width:100; height:100; position:relative;
<html>
<!-- css code -->
<style>
body{background-color:black;}
#a{
width:100;
height:100;
position:relative;
background-color:yellow;
}
#b{
width:50px;
height:50px;
position:absolute;
background-color:blue;
}
#btn{
background-color:orange;
border-radius:4px;
color:white;
}
</style>
<!-- css ends here -->
<!-- html code-->
<body>
<button type="submit" onclick="rn" id="btn">click me</button>
<div id="a">
<div id="b"></div>
</div>
</body>
<!-- html ends here -->
<!-- script starts here -->
<script>
function rn(){
var box = document.getElementById("b");
var pos = 0;
var r = setInterval(move, 5);
function move(){
if (pos == 150){clearInterval(r)
}//if ends
else{
pos +=1;
box.style.left = pos+"px"
}//else ends
}//child function ends
}//parent function ends
</script>
<!-- script ends here -->
</html>
正文{背景色:黑色;}
#a{
宽度:100;
身高:100;
位置:相对位置;
背景颜色:黄色;
}
#b{
宽度:50px;
高度:50px;
位置:绝对位置;
背景颜色:蓝色;
}
#btn{
背景颜色:橙色;
边界半径:4px;
颜色:白色;
}
点击我
函数rn(){
var-box=document.getElementById(“b”);
var-pos=0;
var r=设定间隔(移动,5);
函数move(){
如果(pos==150){clearInterval(r)
}//如果结束
否则{
pos+=1;
box.style.left=pos+“px”
}//其他目的
}//子函数结束
}//父函数结束
只需在单击中将rn更改为rn()。它会起作用的
rn是函数,您希望在单击时执行。只需在单击中将rn更改为rn()。它会起作用的
rn是函数,您希望在单击时执行。将
onclick=“rn”
更改为onclick=“rn()”
。重复。我不确定样式或脚本是否正常工作-它们既不在
中,也不在
中。将onclick=“rn”
更改为onclick=“rn()。”
.replicate of.我不确定样式或脚本是否有效-它们既不在
中,也不在
中。