【发布时间】:2019-03-01 04:34:06
【问题描述】:
<script>
let sectionFlags = {
objective: true; // '} expected'
coursework: true;
education: true;
technicalSkills:true;
}
function toggleSection(id){
sectionFlags[id] { //'} expected'
if(sectionFlags[id]){
$('#' + id.css('display','block'));
}
else {
'none'; //'} expected'
}
}
}
let resume;
function displayObjective() {
$('#objective').html(htmlFrag);
}
function displayFromJson() {
displayObjective(); //'} expected'
$("#objectiveHeading").on('click', {id: 'objective'}, toggleSection) // '} expected'
}
$(document).ready(function(){
$.getJSON('resume.json'), function(resumeData) {
resume = resumeData;
displayFromJson();
});
});
</script>
<script type = "text\javascript" src =
"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>
<script src ='resume.html'></script> // 'JSX expressions must have one parent element'
我遇到了这个 .js 文件的问题。我应该使用 cdn 加载 jquery,从我读过的所有资源中,它是在文件末尾的脚本标记中完成的。经过更多搜索后,我意识到我需要在标签中包含“text\javascript”作为类型,但这并没有解决我的任何错误。据我从搜索中可以看出,我加载正确。
我得到的错误是“} 预期的”和“JSX 表达式必须有一个父元素”。我已经评论了这些错误的位置。任何帮助将不胜感激,据我所知,没有缺少大括号......我正在做的研究没有任何进展。 提前致谢!!
【问题讨论】:
-
你的
let sectionFlags是一个对象,所以应该有逗号而不是分号。这可能会弄乱你脚本的其余部分。 -
到处都是语法错误。如果这是一个
.js文件,则不应有<script>标记。用逗号分隔您的对象属性,即objective: true,。您需要定义jQuery简写$或只使用jQuery代替。即jQuery.getJSON..。src ='resume.html'是错误的 - 那应该是一个js文件。我建议您阅读教程,不要为此感到羞耻。 -
jQuery 也需要被包含在之前你尝试使用它定义的属性。
-
谢谢,这很有帮助!我肯定会做一个教程。
标签: javascript jquery cdn src