语法错误:意外的令牌'<'<doctype html =“”>

时间:2018-08-01 22:45:44

标签: javascript html syntax-error doctype

OMG,我厌倦了试图自己解决这个问题。我正在Chrome和Firefox中使用开发人员工具,但不断收到SyntaxError:Unexpected Token <。它一直标记第一行。请在这里告诉我我在做什么错,谢谢!我已经尝试过YouTube视频和W3schools.com,但仍然无法弄清为什么仍会抛出该视频。

<!DOCTYPE html>
<html lang="en-US">
<head>
<title>Invitation Page</title>
<link rel="stylesheet" type="text/css" href="css/main.css" />
</head>
<script>
function showFormInput() { //get data from the form
var a1 = document.getElementById('rname').value; // 'rname reference 
// id in html(not included with html you will need to add.)
var b2 = document.getElementById('orgname').value;
var c3 = document.getElementById('date').value;
var d4 = document.getElementById('web').value;
var e5 = document.getElementById('hname').value;

document.getElementById('recipientName').innerHTML = a1; // 'recipientName 
// reference name in the html
document.getElementById('organizationName').innerHTML = b2;
document.getElementById('eventDate').innerHTML = c3;
document.getElementById('websiteURL').innerHTML = d4;
document.getElementById('hostName').innerHTML = e5;
}
</script>
<body>
<header>
<div class="top">
<a class="logo" href="index.html">CapellaVolunteers<span 
class="dotcom">.org</span></a>
</div>
<nav>
<ul class="topnav">
<li><a href="index.html">Home</a></li>
<li><a href="invitation.html" class="active">Invitation</a></li>
<li><a href="gallery.html">Gallery</a></li>
<li><a href="registration.html">Registration</a></li>
</ul>
</nav>
</header>
<section id="pageForm">
<label for="recipientName">Recipient name:</label>
<input type="text" id="rname" name="recipientName" placeholder="Enter your 
Recipient Name" />
<label for="organizationName">Organization name:</label>
<input type="text" id="orgname" name="organizationName" placeholder="Enter 
your Organization Name" />
<label for="eventDate">Event Date:</label>
<input type="text" id="date" name="eventDate" placeholder="Enter your 
Event Date" />
<label for="websiteURL">URL:</label>
<input type="text" id="web" name="websiteURL" placeholder="Enter your 
Website URL" />
<label for="hostName">Host name:</label>
<input type="text" id="hname" name="hostName" placeholder="Host Name" />
<input type="submit" value="Submit" onclick="showFormInput()" />
</section> 
<article id="placeholderContent">
<br/>
<br/>
Hello
<span id="recipientName">recipientName</span>!
<br/>
<br/> You have been invited to volunteer for an event held by
<span id="organizationName">organizationName</span> on
<span id="eventDate">eventDate</span>. Please come to the following 
website:
<span id="websiteURL">websiteURL</span> to sign up as a volunteer.
<br/>
<br/> Thanks!
<br/> 
<br/>
<span id="hostName">hostName</span>
</article>
<footer>This events site is for IT-FP3215 tasks.</footer>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

对我来说似乎很好。我不建议将脚本代码放在body标签之外。我会把它放在标签的最后,这样它就不会阻止页面的加载。另外,我将使用“ Brackets”作为此类项目的代码编辑器。它非常有用,您可以下载“ Beautify”作为扩展名,以使代码格式更加美观。