点击图像时出错:意外令牌}
Error when clicking image: Unexpected Token }
我有一个图像,应该在点击它时运行一个函数,但由于一个奇怪的原因,我得到了错误"意外令牌}"。这是我的代码:HTML:
<img src='images/buildings/house_3.png' onClick='selectbuilding('house');'>
Javascript: function selectbuilding(whichbuilding)
{
building = whichbuilding;
buildingselected = 1;
if (building == "house") {
document.getElementById('maparea').innerHTML="<form method='post'><h2>Base</h2><input id='button' type='button' name='button' onclick='myFunction();' value='Close'/><input id='button' type='button' name='button' onclick='checkelement();' value='Upgrade Base'/></form>";
}
if (building == "wood") {
document.getElementById('maparea').innerHTML="<form method='post'><h2>Wood</h2><input id='button' type='button' name='button' onclick='myFunction();' value='Close'/><input id='button' type='button' name='button' onclick='checkelement();' value='Upgrade Wood'/></form>";
}
else {
document.getElementById('selectbuilding').innerHTML="<img src='images/buildings/" + building + "_3.png'>";
}
}
请帮忙!
查看HTML,特别是属性值。解析器如何知道属性值结束于第四个'
,而不是第二个?它不能。
你写的代码相当于
<img onClick='selectbuilding(' />
在内部创建类似
的内容function handler(event) {
selectbuilding(
}
显然不是有效的JavaScript。对函数参数或属性值使用双引号
相关文章:
- React JS:未捕获(在承诺中)语法错误:在位置 0 的 JSON 中意外<令牌
- jQuery$.getJSON抛出意外令牌
- 为什么我在下面的..of循环中得到意外令牌
- 组件中的ReactJS意外令牌
- AngularJS $http GET 请求到本地 JSON 文件返回语法错误:意外令牌]
- 巴别塔,意外令牌 (15:33) ::.
- Sencha 2.0 和 Codeigniter RESTful API 生成未捕获的语法错误:意外令牌:
- 在事件上使用 jquery 时出现意外令牌
- JSON 中位置 4 处的意外令牌<
- 意外令牌 ) 在我的代码中
- Electron 和 Babel 6 异步/等待抛出意外令牌
- “JSON.parse(str)”返回“意外令牌c”,但str是一个字符串
- jQuery after() uncatch SyntaxError: 意外令牌 ILLEGAL
- 使用节点javascript的意外令牌ILLEGAL
- Javascript/JQuery-Chrome意外令牌
- Ajax 帖子未捕获语法错误:意外令牌非法
- angularjs-SyntaxError:请求从服务器返回时出现意外令牌
- jquery:使用ember的意外令牌C
- React本机项目中的意外令牌
- 解析有效的 JSON 得到“语法错误:意外令牌非法”