為什么一下代碼少了<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">這句div塊就可以成功的移動了?????<html ><head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <title>Document</title> <style type="text/css">? ? ? ? ?.class1? ? {? ? ? ? width:100px;? ? ? ? height:100px;? ? ? ? background-color:Blue;? ? ? ? position:absolute;? ? ? ? ?left:100px;? ? ? ? ? top:100px;? ? } </style> <script type="text/javascript">? ? ? ? ?function show(){? ? ? ? ? var box=document.getElementById('box');? ? ? ? ? var x = box.offsetLeft? ? ? ? ??? ? ? ? ? ? x += 0.5;//每隔40毫秒就向右移動0.5位置? ? ? ? ??? ? ? ? ? ? box.style.left = x;//為什么不可以直接使用left來計算呢因為進行加法運算時,必須是數字而left接受的值是字符串所以需要中間變量來調解? ?? ? ? ? ?}? ? ? ? ?function Move(){? ? ? ? ? setInterval('show()', 40);? ? ? ? ?} </script></head><body> <input type="button" value="右移" onclick="Move();"/> <div id="box" class="class1"></div> </body></html>
- 4 回答
- 0 關注
- 2086 瀏覽
相關問題推薦
添加回答
舉報
0/150
提交
取消