js方法: 複製程式碼 程式碼如下: New Document <br> window.onload=function(){<br> //写入<br> var oneInner = document.createElement("div");<br> oneInner.setAttribute("style","background:#663398;position:absolute;width:100px;height:100px;border:solid 3px #2F74A7;cursor:pointer;");<br> var oneButton = document.createElement("input");<br> oneButton.setAttribute("type","button");<br> oneButton.setAttribute("value","x");<br> if (oneButton.style.cssFloat)<br> {<br> oneButton.style.cssFloat="right"<br> }<br> else<br> {oneButton.style.styleFloat="right"}<br> oneInner.appendChild(oneButton);<br> document.body.appendChild(oneInner);<br><br> //定时器<br> var a1a = setInterval(moves,100);<br> //函数 <p> var x = 10;<br> var y = 10;</p> <p> function moves(){<br> var tops = oneInner.offsetTop<br> var lefts = oneInner.offsetLeft</p> <p> if (lefts>=document.documentElement.clientWidth-oneInner.offsetWidth||lefts<=0)<BR> {<BR> x=-x<BR> }</P><P> <BR> y=-y<BR> 上衣=y;<BR> 左=x;<br> <br> oneInner.style.top=tops "px"<BR> > }</P> <P> //暫停<BR> clearInterval(a1a);<BR> }</P> oneInner.onmouseout=function(){ <P> a1a =setInterval(moves,100);<BR> // 刪除<BR> oneButton.onclick=function(){<BR> ;<BR> }<BR> }<BR> <身體>