javascript - JQuery 无法分配给“#back”上的属性“guid”:不是对象
问题描述
我正在编写一个 Node.js 游戏,我正在使用 jquery 将所有按钮点击绑定到方法。我的大部分工作,除了一个。它抛出错误can't assign to property "guid" on "#back": not an object
Back is a button in my html 文件。
我的 html 页面只是一个页面,其中包含一堆不同的脚本,当它们需要被 dipalyed 时,我将它们插入到 gameArea div 中。这是我用于后退按钮的脚本的示例。
<script id="hostJoinGame" type="text/template">
<h1>The host has join the game</h1>
<button id="startGame"> StartGame </button>
<button id='back'>Back</button>
</script>
init: function() {
App.cacheElements();
App.showInitScreen();
App.bindEvents();
},
cacheElements: function () {
App.$doc = $(document)
//host screens
App.$gameArea =$('#gameArea');
App.$introScreen = $('#intro-screen').html();
App.$hostJoinGame = $('#hostJoinGame').html();
App.$hostWaitingScreen = $('#roundStart').html();
App.$hostDuelScreen = $('#hostDuelScreen').html();
App.$hostDisplayLeaderboard = $('#hostDisplayLeaderboards').html();
App.$endOfGame = $('#endOfGame').html();
//player screens
App.$playerJoinGame = $('#playerJoinGame').html();
App.$playerSetsName = $('#playerSetsName').html();
App.$playerAnswer = $('#playerAnswer').html();
App.$playerWaitingScreen = $('#playerWaitingScreen').html();
App.$playerVotingScreen = $('#playerVotingScreen').html();
}, /**
* Listens for events on the webpage
*/
bindEvents: function () {
App.$doc.on('click', '#createGame', App.Host.onCreateClick);
App.$doc.on('click', "#joinGame", App.Player.onJoinClick);
App.$doc.on('click', "#startGame", App.Host.startGame);
App.$doc.on('click', "#submit", App.Player.setName);
App.$doc.on('click', "#back", App.showInitScreen);
// App.$doc.on('submit', "#answerSubmit", App.Game.Answer);
//App.$doc.on('click', "#box1", App.Player.vote(1));
//App.$doc.on('click', "#box2", App.Player.vote(2));
//App.$doc.on('click', "#playAgain", App.Host.startGame());
//App.$doc.on('click', '#quit', App.showInitScreen);
},
showInitScreen: function () {
App.$gameArea.html(App.$introScreen);
},
这是我在 chrome 控制台中收到的错误消息
Uncaught TypeError: can't assign to property "guid" on "#back": not an object
jQuery 6
add
on
each
each
on
on
bindEvents http://localhost:3000/app.js:113
init http://localhost:3000/app.js:81
<anonymous> http://localhost:3000/app.js:368
jQuery 2
mightThrow
process
jquery.3.6.0.js:5221:4
jQuery 6
bindEvents http://localhost:3000/app.js:113
init http://localhost:3000/app.js:81
<anonymous> http://localhost:3000/app.js:368
jQuery 2
mightThrow
process
我不确定为什么 jquery 试图将我的 html 中的脚本 id 绑定到一个对象中。谢谢您的帮助。
解决方案
推荐阅读
- ios - 是否可以从最近删除的照片中恢复?
- python - 为什么我在 BeautifulSoup 文档中找不到任何关于 .text 或 content 方法的内容?
- python - Python:如何用直线替换圆内的曲线点?
- docker - NGINX 反向代理配置结构
- node.js - 如何将子接口传递给父类?
- angular - 离子生产构建模块构建失败 webpack
- python - 将变量从 STT 传递到 url 在 Python 中被分开
- xampp - XAMP 中的 MYSQL 服务器不运行
- macos - 从 MAC 到具有特殊文件系统的远程 DataDomain 的 ansible
- php - Laravel 中的动态滑块