html - 选择禁用选项的发布值
问题描述
当用户不选择该选项时,我想发布价值,但是
<select name="nowEdu_level" class="form-control">
<option disabled="" selected="" value="0"></option> //this is the Disable Option
<option value="level_bacDe">Bachelor Degree</option>
<option value="level_masDe">Master Degree</option>
<option value="level_other">Other Graduate</option>
</select>
但是当我提交这个帖子的值为 "None" 时,我想在用户不选择选项时发布 "0"
请帮助我,我是初学者
解决方案
function myFunction() {
debugger;
var e = document.getElementById("mySelect");
var strUser = e.options[e.selectedIndex].value;
console.log(strUser);
}
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form>
Select your favorite fruit:
<select id="mySelect" name="nowEdu_level" class="form-control">
<option disabled="" selected="" value="0" ></option> //this is the Disable Option
<option value="level_bacDe">Bachelor Degree</option>
<option value="level_masDe">Master Degree</option>
<option value="level_other">Other Graduate</option>
</select>
</form>
<p>Click the button to return the value of the selected fruit.</p>
<button type="button" onclick="myFunction()">Post</button>
<p id="demo"></p>
</body>
</html>
这将为您提供默认选定项目的值。
推荐阅读
- json - Using nested JSON data in D3
- asp.net-core - ASP.NET Core - 有没有办法使用自定义标签助手来呈现一组元素?
- python - 为什么空的 MySQL 数据库声称有重复项(Python 3)?
- sql - 如何在 postgres 中运行 50 个数据库中的查询?
- python - pytest:如果设置出现问题,如何跳过测试用例并直接进行清理?
- google-cloud-platform - 将 Colab 连接到付费 TPU
- c# - Unable to create an object of type 'ApplicationDbContext'. For the different patterns supported at design time
- amazon-web-services - AWS Glue not deleting or deprecating tables generated over now removed S3 data
- java - 如何从集合中获取特定数据?(调试器)
- react-native - 反应原生 | 在组件之间传递数据