【发布时间】:2014-09-14 20:01:48
【问题描述】:
我有一个带有自定义模板的“国际象棋”页面。当我在线使用cheessboard.js 脚本时没有问题。当我想使用它的下载版本并将<base href="http://chessboardjs.com/" /> 替换为本地路径时,它会在浏览器上产生以下错误:
GET http://localhost/css/chessboard.css (index):4
GET http://localhost/js/chess.js (index):8
GET http://localhost/js/jquery-1.10.1.min.js (index):9
GET http://localhost/js/chessboard.js (index):10
Uncaught ReferenceError: $ is not defined
如何调整模板Chess.php?
...
<html>
<head>
<base href="http://chessboardjs.com/" />
<link rel="stylesheet" href="/css/chessboard.css" />
</head>
<body>
<div id="board" style="width: 400px"></div>
<script src="/js/chess.js"></script>
<script src="/js/jquery-1.10.1.min.js"></script>
<script src="/js/chessboard.js"></script>
<script>
var init = function() {
var board, game = new Chess();
var makeRandomMove = function() {
var possibleMoves = game.moves();
if (game.game_over() === true || game.in_draw() === true || possibleMoves.length === 0) return;
var randomIndex = Math.floor(Math.random() * possibleMoves.length);
game.move(possibleMoves[randomIndex]);
board.position(game.fen());
window.setTimeout(makeRandomMove, 500);
};
board = new ChessBoard('board', 'start');
window.setTimeout(makeRandomMove, 500);
};
$(document).ready(init);
</script>
</body>
</html>
...
【问题讨论】:
-
浏览器 JavaScript 控制台中是否有任何错误?
-
“它不起作用”是NO错误描述
标签: javascript php wordpress chessboard.js