baidu_32147215 2015-10-19 14:52 采纳率: 0%
浏览 1734

一个JS小程序出现了超级奇怪的bug,实在找不到问题求大神支招


 <!DOCTYPE html>
<html>
<head>
    <title>Hello World</title>
    <link rel="stylesheet" type="text/css" href="Marion.css">
    <script language="javascript" type="text/javascript">
        function marion () {
            this.x=0;
            this.y=0;
            this.move=function(direct){
                var myimg=document.getElementById("img12");
                var left=myimg.style.left;
                left=left.substr(0,(left.length-2));
                var top=myimg.style.top;
                top=top.substr(0,(top.length-2));
                switch(direct){
                    case '0':window.alert(myimg.style.left+"+"+myimg.style.top);
                    myimg.style.top=(top-40)+"px";break;
                    case '1':myimg.style.left=(left-40)+"px";break;
                    case '2':myimg.style.top=(top+40)+"px";break;
                    case '3':myimg.style.left=(left+40)+"px";break;

                }
            }
        }
        var mario=new marion();
        function marionmove(direct){
            mario.move(direct);
        }
    </script>
</head>
<body>
<div class="Marion">
    <img id="img12" src="aa.jpg"  class="img1"/>
</div>
<table border="1" style="margin: 0 0 0 500px">
    <tr><td colspan="3" align="center">游戏键盘</td></tr>
    <tr><td></td><td><input type="button" value="↑" onclick="marionmove('0')"/></td><td></td></tr>
    <tr><td><input type="button" value="←" onclick="marionmove('1')"/></td><td><input type="button" value="↓" onclick="marionmove('2')"/></td><td><input type="button" value="→" onclick="marionmove('3')" /></td></tr>
    </table>
</body>
</html>




  • 写回答

4条回答 默认 最新

  • baidu_32147215 2015-10-19 14:56
    关注

    <!DOCTYPE html>


    Hello World

    <br> function marion () {<br> this.x=0;<br> this.y=0;<br> this.move=function(direct){<br> var myimg=document.getElementById(&quot;img12&quot;);<br> var left=myimg.style.left;<br> left=left.substr(0,(left.length-2));<br> var top=myimg.style.top;<br> top=top.substr(0,(top.length-2));<br> switch(direct){<br> case &#39;0&#39;:window.alert(myimg.style.left+&quot;+&quot;+myimg.style.top);<br> myimg.style.top=(top-40)+&quot;px&quot;;break;<br> case &#39;1&#39;:myimg.style.left=(left-40)+&quot;px&quot;;break;<br> case &#39;2&#39;:myimg.style.top=(top+40)+&quot;px&quot;;break;<br> case &#39;3&#39;:myimg.style.left=(left+40)+&quot;px&quot;;break;</p> <pre><code> } } } var mario=new marion(); function marionmove(direct){ mario.move(direct); } &lt;/script&gt; </code></pre> <p></head><br> <body></p> <div class="Marion"> <img id="img12" src="aa.jpg" class="img1"/> </div> <table border="1" style="margin: 0 0 0 500px"> <tr><td colspan="3" align="center">游戏键盘</td></tr> <tr><td></td><td><input type="button" value="↑" onclick="marionmove('0')"/></td><td></td></tr> <tr><td><input type="button" value="←" onclick="marionmove('1')"/></td><td><input type="button" value="↓" onclick="marionmove('2')"/></td><td><input type="button" value="→" onclick="marionmove('3')" /></td></tr> </table> <p></body><br> </html><br> 上面的代码发瞎了。。</p>
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!