简体   繁体   English

标签元素的for属性的值必须是非隐藏表单控件的ID吗?

[英]The value of the for attribute of the label element must be the ID of a non-hidden form control?

I'm trying to create a website for a class project. 我正在尝试为课程项目创建一个网站。 One of the pages has to be a form. 页面之一必须是表单。 For my form, when I coded the labels, I got a "The value of the for attribute of the label element must be the ID of a non-hidden form control" error for each label when I went to validate it, despite the fact that the site works as intended. 对于我的表单,当我对标签进行编码时,我去验证每个标签时,对于每个标签,我都收到“标签元素的for属性值必须是非隐藏表单控件的ID”错误,该网站可以按预期工作。 How can I fix it Can it be fixed? 我该如何解决?可以解决吗? Here's the code for the webpage: 这是该网页的代码:

<!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 &copy; 2020 InTheKnow.com<br>
  <a href="mailto:gsingletary4@centralgatech.edu"></a> gsingletary4@student.centralgatech.edu
  </footer>
 </div>
</body>
</html>

Your issue is happening in the label/inputs you have where your label's have for attributes but your inputs don't have id attributes. 你的问题是发生在标签/输入,让您设定标签的都for属性,但你的投入没有id属性。 You can fix this as follows: 您可以按以下方式解决此问题:

<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">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM