为什么在脚本的第一行出现JS错误语法错误:无效或意外的令牌? [英] Why am I getting the JS error in line one of my script Syntax error: invalid or unexpected token?
本文介绍了为什么在脚本的第一行出现JS错误语法错误:无效或意外的令牌?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当您按下按钮时,我正在尝试更改index.html页面上的图片.这是我的HTML:
I'm trying to make the picture on the index.html page change when you push the button. Here's my HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<button id="lolcatButton">Show me the LOLCat!</button>
<br><br>
<img id="lolcatImage" src=https://s3.amazonaws.com/media.skillcrush.com/skillcrush/wp-content/uploads/2016/09/cat5.jpg>
<script src="script.js"></script>
</body>
这是我的js:
And here's my js:
var lolcatButton = document.getElementById("lolcatButton");
var lolcatImage = document.getElementById("lolcatImage");
var image = "https://s3.amazonaws.com/media.skillcrush.com/skillcrush/wp-content/uploads/2016/09/cat4.jpg";
var showMeTheLolcat = function(){
lolcatImage.src = image;
};
lolcatButton.addEventListener("click", showMeTheLolcat);
我在js的第1行出现错误未捕获的语法错误:无效或意外的令牌."
I'm getting an error on line 1 of the js "uncaught syntaxerror: invalid or unexpected token."
有人有什么想法吗?非常感谢你!
Does anyone have any ideas? Thank you very much!
推荐答案
var lolcatButton = document.getElementById("lolcatButton");
将" 更改为" .以及其他几行.
Change the " to ". And the other lines.
这篇关于为什么在脚本的第一行出现JS错误语法错误:无效或意外的令牌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文