简体   繁体   English

我的 html/javascript/css 网站在 IE 中工作,但在 FF 中不工作

[英]My html/javascript/css site works in IE but not in FF

www.warhawkcomputers.com/Birenbaum www.warhawkcomputers.com/Birenbaum

This site has various projects for my Computer class that I am in. A check is coming up and all programs will need to work in FF and IE.该站点为我所在的计算机 class 提供了各种项目。即将进行检查,所有程序都需要在 FF 和 IE 中运行。

My Bouncing Ball, Race Track, and Tanks projects under Third quarter as well as pong under Fourth Quarter work in IE when the objects need to be moved by a continuously adding variable performed in a javascript script, and it works perfectly fine in IE, but when viewed with Firefox 3, the moving objects no longer move and I have tested to find out it gets the variables but seems to only add it once and that the document.getElementById("objectname").style.left = "continuously adding variable" seems to not be executed despite being in a timer running every 10 milliseconds.当需要通过在 javascript 脚本中执行的连续添加变量来移动对象时,我的第三季度下的弹跳球、赛道和坦克项目以及第四季度下的 pong 在 IE 中工作,并且它在 IE 中运行良好,但是当使用 Firefox 3 查看时,移动对象不再移动,我已经测试发现它得到了变量,但似乎只添加了一次,并且document.getElementById("objectname").style.left = "不断添加变量" 尽管处于每 10 毫秒运行一次的计时器中,但似乎没有执行。

Also, none of my keypress code works in Firefox, but I believe that is because I use an outdated method of moving objects via keypress.另外,我的keypress代码在 Firefox 中都不起作用,但我相信这是因为我使用了一种过时的通过按键移动对象的方法。 This is largely due to my teacher's outdated methods.这很大程度上是由于我老师的过时方法。

Thanks for all of your guys's help.感谢你们所有的帮助。

You need to add a 'units' to your positions:您需要在您的职位上添加一个“单位”:

document.getElementById("ball").style.left = x + 'px';
document.getElementById("ball").style.top = y + 'px';

That will work in FF as well now.这现在也适用于 FF。

Firefox does not use a global event object. Firefox 不使用全局event object。 They pass an event object into the handler.他们将事件 object 传递给处理程序。 As a result, you need to modify your Move function:因此,您需要修改您的Move function:

function Move(e) {
    /* snip */
    var whichkey = window.event ? window.event.keyCode : e.keyCode;
    /* ... */

Gerrat is absolutely correct about the other problem you asked about.杰拉特关于你问的另一个问题是绝对正确的。

EDIT : this won't work with how you hooked your event handler in the body tag.编辑:这不适用于您将事件处理程序挂接到 body 标记中的方式。 You need to remove the onkeydown="Move()" attribute from the body tag and add the following code at the top of JavaScript.js :您需要从 body 标记中删除onkeydown="Move()"属性,并在JavaScript.js的顶部添加以下代码:

document.body.onkeydown=Move;

If allowed to do so by your teacher, you would be MUCH better off using jQuery or some other framework.如果您的老师允许这样做,您最好使用 jQuery 或其他一些框架。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM