English 中文(简体)
拒绝工作?
原标题:Javascript refusing to work?

我利用“超声5”的手法,与大鼠进行很少的游戏。 我将信道和信tag带在“html”档案中,把 j印在称为“java”的 se中。 js。

在我把html装入我的浏览器时,我随时提醒大家注意。 问题在于它没有显示其中的任何部分,也没有显示单体的负荷。

最好的是火力: 在“超文本”栏下,当我点击标语时,它向我展示了全稿,但在“文字”栏下,它告诉我,该页上没有字母。

Help?

阁下:

    <body><canvas id="canvas" width="1000px" height="500px" style="border:1px solid #c3c3c3;">text</canvas>
<script type="text/javascript" src="java.js">
</script></body>

当我把文字标签放在头上:

<head><script type="text/javascript" src="java.js">
    </script></head> 
<body><canvas id="canvas" width="1000px" height="500px" style="border:1px solid #c3c3c3;">text</canvas>
    </body>

我的 j:

alert( define );
var scrollx=0,
scrolly=0,
keyID=0,
global = {};
global.players=[];
global.playermap=[];
var c=document.getElementById("canvas"),
ctx=c.getContext( 2d );
alert( init );

function pony (x,y, hspd, vspd) {
alert("pony created!");
this.x = x;
this.y = y;
this.vsp = vspd;
this.hspd = hspd;
this.image = new Image();
this.image.src = "alien.png";
this.framenumber = 11;
this.frameactual = 1;
this.framespeed=0.8;
this.frametime =50;
this.framewidth = this.image.width / this.framenumber;
this.frameheight = this.image.height;
this.colorbody="#000000";
//
this.nextframe = function() {
this.frameactual=this.frameactual+this.framespeed;
if (Math.round(this.frameactual)>this.framenumber){this.frameactual=1;}
this.draw();
};
//
this.draw = function() {
this.frame=Math.round(this.frameactual);
ctx.drawImage(this.image,(this.frame-1)*this.framewidth,0,this.framewidth,this.image.height,this.x-scrollx-(this.framewidth/2),this.y-scrolly-(this.image.height/2),this.framewidth,this.image.height);
};
//
//var _this=this;
//this.frametimer=setInterval(function(){_this.nextframe();},this.frametime);
alert("time set");
}
//
function setpos_player(id,x,y,hspd,vspd){
alert("this");
if (typeof(global.playermap[id])=="undefined"){
global.players.push(new pony (x,y, hspd, vspd));
global.playermap[id]=global.players.length;}
else{
global.players[global.playermap[id]].x=x;
global.players[global.playermap[id]].y=y;
global.players[global.playermap[id]].hspd=hspd;
global.players[global.playermap[id]].vspd=vspd;}
}
//
function clear(){
    ctx.fillStyle = "#FFFFFF";
    ctx.beginPath();
    ctx.rect(0,0,1000,1000);
    ctx.closePath();
    ctx.fill();}

document.onkeypress = KeyCheck; 
document.onkeydown = KeyCheck;     
document.onkeyup = KeyRelease;   

function KeyCheck(e)

{
   keyID = (window.event) ? event.keyCode : e.keyCode;
   }
function KeyRelease(e)
{keyID=0;}

//
function step(){
clear();
for (var i = 0; i < global.players.length; i++) {
    _this=global.players[i];
    _this.y+=_this.vspd;
    _this.nextframe();
    //Do something
}
//global.players[1].nextframe();
timer=setTimeout(function(){step();},80);
}
setpos_player(1,200,200,0,1);
var timer=setTimeout(function(){step();},80);
最佳回答

参看你这里的错误:

if (typeof(global.playermap[id])="undefined"){

应当:

if (typeof(global.playermap[id])=="undefined"){

并试图取代所有<代码>alert 电话:console.log,然后对rs子进行检查。

问题回答

declare script before you use it in the html you can put that script in head of the page like this

<head>
<script type= text/javascript  src= java.js ></script>
</head>

一劳永逸地进行审判,并在此重新发挥作用

if (typeof(global.playermap[id])="undefined"){

页: 1

if (typeof global.playermap[id] == "undefined"){

要求为档案设置正确的目录。 例如,它可能是/java.js或“/scripts/java.js”。

如果您的警惕性减弱,就会显示是否装载了 j。

并且,你应当知道,在欧洲复兴开发银行一节中应当加上外面的文字标签。





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签