简体   繁体   English

添加所需属性后,选择框验证出现问题

[英]Select box validation is having problem after adding a required attribute

I got a problem when I'm validating this. 验证时出现问题。 I can't understand how do I fix it? 我不明白该如何解决?

 <Label for="religion">Select Your Religion</Label> <select required class="form-control" id="religion"> <option disabled>Select Your Religion</option> <option value="hindu">Hindu</option> <option value="muslim">Muslim</option> <option value="christian">Christian</option> <option value="buddhist">Buddhist</option> <option value="other">Other</option> </select> 

Here is the problem I'm getting on https://validator.w3.org/nu : 这是我在https://validator.w3.org/nu上遇到的问题:

The first child option element of a select element with a required attribute, and without a multiple attribute, and without a size attribute whose value is greater than 1, must have either an empty value attribute, or must have no text content. select元素的第一个子选项元素,具有必需属性,没有多重属性,并且没有大于1的大小属性,必须具有空值属性或没有文本内容。 Consider either adding a placeholder option label, or adding a size attribute with a value equal to the number of option elements. 考虑添加占位符选项标签,或者添加大小等于选项元素数量的size属性。

name tag is missing for your select option 您选择的选项缺少名称标签

Also, the select option should have value="" 另外,选择选项应具有value =“”

<Label for="religion">Select Your Religion</Label>
<select required name="religion" class="form-control" id="religion">
   <option value="">Select Your Religion</option>
   <option value="hindu">Hindu</option>
   <option value="muslim">Muslim</option>
   <option value="christian">Christian</option>
   <option value="buddhist">Buddhist</option>
   <option value="other">Other</option>
</select>

Like the validator message says 就像验证器消息说

...must have either an empty value attribute, or must have no text content... ...必须具有空值属性,或必须没有文本内容...

Make sure your option has an empty value, like <option disabled value=""> 确保您的选项具有空值,例如<option disabled value="">

 <Label for="religion">Select Your Religion</Label> <select required class="form-control" id="religion"> <option disabled value="">Select Your Religion</option> <option value="hindu">Hindu</option> <option value="muslim">Muslim</option> <option value="christian">Christian</option> <option value="buddhist">Buddhist</option> <option value="other">Other</option> </select> 

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

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