我已经在超文本标记语言<Select>
中应用了<Required>
标签,但不起作用。即使在第一步不选择任何内容,表单仍然能够继续进行下一步。有人知道怎么解决这个问题吗?
<label>Region :</label>
<select id="Region" class="custom-select form-control" required>
<option value="">Select Region</option>
<option value="central" id="Central">Central</option>
<option value="northern" id="Northern">Northern</option>
</select>
发布于 2019-05-24 00:11:03
你用HTML5声明你的网页了吗?确保在页面的开头声明以下语句
<!DOCTYPE html>
required
属性仅在HTML5中可用,并且仅受特定浏览器支持...w3schools Required Attribute
在HTML5中测试了原始代码后,它就可以工作了。
发布于 2019-05-24 00:11:06
您可以完全去掉select option标记,并将值select option
放入select标记本身。
<label>Region:</label>
<select value="Select Option" id="Region" class="custom-select form- control" required>
<option value="central" id="Central">Central</option>
<option value="northern" id="Northern">Northern</option>
</select>
发布于 2019-05-24 07:35:11
您的代码是否工作取决于您使用的浏览器或您使用它的方式。我为你写了一个示例代码。希望它能帮助你:
<!DOCTYPE html>
<html>
<body>
<form >
<label>Region :</label>
<select id="Region" class="custom-select form-control" required>
<option value="">Select Region</option>
<option value="central" id="Central">Central</option>
<option value="northern" id="Northern">Northern</option>
</select>
<input type="submit">
</form>
</body>
</html>
因此,在上面的代码中,如果您没有选择任何内容,它将不会让您提交。
https://stackoverflow.com/questions/56278993
复制相似问题