gpt4 book ai didi

JavaScript 文件作为空白

转载 作者:行者123 更新时间:2023-11-28 00:16:28 25 4
gpt4 key购买 nike

不确定这里发生了什么。最初我在script.js中有一些代码但现在它已被重构并准备好放入自己的文件中。因此,在完成重构后,我将代码移至 base.js 。这是 html。

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Cache-control" content="no-cache">
<title>Draw</title>
<link rel='stylesheet' type='text/css' href='style.css'/>
<script src="libraries/jquery-2.1.4.js"></script>
</head>
<body>
<canvas id="canvas">
HTML5 Canvas not supported.
</canvas>

<script type="text/javascript" src="base.js"></script>
<script type="text/javascript" src="script.js"></script>
</body>
</html>

但出于某种原因,base.js在 chrome 开发者工具中显示为空,并且 script.js提示它找不到 base.js 中定义的原型(prototype)。

我知道这个 URL 是好的,因为我故意拼写错误,并且在开发者控制台中它向我大喊大叫,说在我更正拼写之前无法找到它。我知道它没有被缓存,因为我已经清除了缓存。最后,我尝试将名称更改为 base_prototype.js并且它有效。

为什么会发生这种情况?

编辑:添加 script.js base.js

//script.js
/**
* Created by carlos on 5/20/15.
*/
var myBase;

$(function() {
myBase = new Base(document.getElementById("canvas"));
myBase.draw(minDim());



});

$( window ).resize(function() {
myBase.draw(minDim());
});

function minDim(){
return Math.min($(window).height(),$(window).width());

}

//base.js
/**
* Created by carlos on 5/23/15.
*/
function Base(canvas){
this.canvas = canvas;
this.context = this.canvas.getContext("2d");
this.grids = 40;
this.canvasSize = 0;
this.draw = function(size){
this.canvasSize = size;
this.canvas.width = size;
this.canvas.height = size;
$( this.canvas ).height(size);
$( this.canvas ).width();

this.drawZeroMatrixStockGrid(0,this.grids,0,this.grids);

this.context.stroke();
};

this.drawZeroMatrixStockGrid = function (startX, endX, startY, endY){
var adjust = this.grids/2;
this.drawMatrixStockGrid(startX-adjust , endX-adjust , startY-adjust, endY-adjust);
};
this.drawMatrixStockGrid = function(startX, endX, startY, endY){

this.context.beginPath();
this.context.transform(.5, -.5, .5, .5, this.canvasSize/2, this.canvasSize/2);
this.context.scale(1,1);
for(var x = startX;x<endX + 1 ;x++){
this.context.moveTo(this.getXCoord(this.canvasSize,this.grids,x),this.getYCoord(this.canvasSize,this.grids,startY));
this.context.lineTo(this.getXCoord(this.canvasSize,this.grids,x),this.getYCoord(this.canvasSize,this.grids,endY));
}

for(var y = startY;y<endY + 1;y++){
this.context.moveTo(this.getXCoord(this.canvasSize,this.grids,startX),this.getYCoord(this.canvasSize,this.grids,y));
this.context.lineTo(this.getXCoord(this.canvasSize,this.grids,endX),this.getYCoord(this.canvasSize,this.grids,y));
}

};


/**
* assumes a square canvas
* TODO use global vars to clean signature
* TODO memoize
* */
this.getXCoord = function (canvasSize, grids, coord){
var delta = canvasSize/(grids);
return delta*coord;
};
this.getYCoord = function(canvasSize, grids, coord){
var delta = canvasSize/(grids);
return delta*coord;
};


}

最佳答案

如果您可以通过 file://但不能通过 http://在本地查看文件,则问题很可能来自服务器设置。响应处理程序可以在没有警告的情况下覆盖您的静态文件并发送成功的状态调用。

正如您通过我们的评论发现的那样,REST Controller 确实将 GET 请求映射到“[/base]”模式,覆盖与 Assets 名称匹配的静态文件的任何尝试。更改文件名是解决问题的最快途径,至少在前端是这样。

干杯!

关于JavaScript 文件作为空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30425416/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com