语法错误:预期前pression,拿到了'&LT;',这是什么意思? [英] SyntaxError: expected expression, got '<', what does that mean?
问题描述
我知道这是问了几次上S.O。
I know this is asked a few times on S.O.
但没有答案似乎符合我的情况。所以,我有一个它试图使用一个外部JS一个基本的HTML页面。 JS文件试图改变在按钮上点击HTML定义一个段落的内容,但似乎并没有工作。
but none of the answers seem to match my situation . So, I have a a basic Html page which tries to use an external JS. The JS file tries to change the content of a paragraph defined in the HTML on a button click, but does not seem to work.
我看到下面的错误控制台:
I see the following errors in console :
1)语法错误:预期前pression,拿到了'&LT;
1)SyntaxError: expected expression, got '<'
2)的ReferenceError:变化是没有定义
2)ReferenceError: change is not defined
的jsfiddle显示确切的来源(除&放大器;标记为删除的jsfiddle - http://jsfiddle.net/p9ko4yde/
JSFiddle showing exact source?(except that & tags are removed as jsfiddle - http://jsfiddle.net/p9ko4yde/
HTML code:
HTML Code :
<h1> Numbers with external script:) </h1>
<p id="number">1</p>
<button type="button" onclick="change()">Toggle between 1 and 2</button>
<script src="myScript.js"></script>
</body>
</html>
JS code:
JS Code :
<script type="text/javascript">
function change(){
var number = document.getElementById('number').innerHTML;
if(number == '1'){
document.getElementById('number').innerHTML='2';
}
else{
document.getElementById('number').innerHTML='1';
}
}
</script>
推荐答案
您不需要&LT;脚本&GT;
标签时在外部.js文件。使用这些标签嵌入在HTML中的脚本只。
You don't need the <script>
tags when in an external .js file. Use these tags to embed a script inside HTML only.
这篇关于语法错误:预期前pression,拿到了'&LT;',这是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!