我正在尝试为课程项目创建一个网站。页面之一必须是表单。对于我的表单,当我对标签进行编码时,我去验证每个标签时,对于每个标签,我都收到“标签元素的for属性的值必须是非隐藏表单控件的ID”错误,该网站可以按预期工作。如何解决?可以解决吗?这是该网页的代码:
<!DOCTYPE html>
<html lang="en">
<head>
<title>In The Know :: Subscribe</title>
<meta charset="utf-8">
<link href="intheknow.css" rel="stylesheet">
<meta name="description" content="InTheKnow.com is your go-to site for whenever you want to catch up on the latest stories about everything from Hollywood happenings to world events.">
</head>
<body>
<div id="container">
<header>
<h1><a href="index.html">InTheKnow.com</a></h1>
</header>
<nav>
<ul>
<li><a href = "index.html">Home</a></li>
<li><a href = "subscribe.html">Subscribe</a></li>
<li><a href = "topics.html">Topics</a></li>
</ul>
</nav>
<main>
<h1>Subscribe To Stay In The Know</h1>
<h2>Knowledge is Power. Get The Power To Stay Ahead.</h2>
<hr>
<figure id="subpagepic">
<img src="fishingboat.jpg" alt="InTheKnow.com" width="200" height="200">
<figcaption> Get your info ship sailing<br>
with a subscription today!</figcaption>
</figure>
<h3>Enter Your Basic Information</h3>
<form method="post" action="mailto:gsingletary4@centralgatech.edu">
<label for="myFirstName"> First Name:</label>
<input type="text" name="myFirstName" required="required">
<label for="myLastName"> Last Name:</label>
<input type="text" name="myLastName" required="required">
<label for="myEmailAddress"> Email Address:</label>
<input type="text" name="myEmailAddress" required="required">
<h3>Choose Your Billing Cycle</h3>
<input type="radio" name="entry" id="entry1">$10/mo <br>
<input type="radio" name="entry" id="entry3">$25/3mo<br>
<input type="radio" name="entry" id="entry6">$50/6mo<br>
<input type="radio" name="entry" id="entry12">$80/12mo<br>
<h3>Choose Your Preferred Payment Method</h3>
<select size="1" name="prefpay" id="prefpay">
<option value="Visa">Visa</option>
<option value="MasterCard">MasterCard</option>
<option value="Discover">Discover</option>
<option value="Chase">Chase</option>
<option value="CapitalOne">Capital One</option>
<option value="AmericanExpress">American Express</option>
</select>
<h3>Preferences/Terms of Service</h3>
<div id="checkbox">
<input type="checkbox" name="notifications" id="notifications" value="yes"> Keep me updated with daily notifications.<br>
<input type="checkbox" name="digital" id="digital" value="yes"> Send me a monthly digital newspaper via email.<br>
<input type="checkbox" name="terms" id="terms" value="yes"> By signing up, you agree to the Terms of Service.<br>
</div>
<h3>Questions/Comments/Concerns?</h3>
<label for="myCommentSection"> Comments: </label>
<textarea name="myCommentSection" id="myCommentSection" rows="3" cols="15"></textarea>
<div id="resetbutton">
<input type="reset">
</div>
<br>
<div id="submitbutton">
<input type="submit" value="Sign me up!">
</div>
</form>
<h3>Questions? Comments? Concerns? Contact us below!</h3>
<div id="contactinfo">
<span class="know">InTheKnow.com</span> <br>
6937 Redwing Drive<br>
Canton, OH 31415<br>
Find us on Facebook: Facebook.com/InTheKnow<br>
Follow us on Twitter: Twitter.com/intheknow<br>
Phone: 987-654-3210<br>
<br>
</div>
</main>
<footer>
Copyright © 2020 InTheKnow.com<br>
<a href="mailto:gsingletary4@centralgatech.edu"></a> gsingletary4@student.centralgatech.edu
</footer>
</div>
</body>
</html>
最佳答案
您的标签/输入中发生了您的问题,其中的标签具有for
属性,但是输入中没有id
属性。您可以按以下方式解决此问题:
<label for="myFirstName"> First Name:</label>
<input type="text" id="myFirstName" name="myFirstName" required="required">
<label for="myLastName"> Last Name:</label>
<input type="text" id="myLastNamr" name="myLastName" required="required">
<label for="myEmailAddress"> Email Address:</label>
<input type="text" id="myEmailAddress" name="myEmailAddress" required="required">