首页 > 解决方案 > 选择禁用选项的发布值

问题描述

当用户不选择该选项时,我想发布价值,但是

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

请帮助我,我是初学者

标签: htmlpost

解决方案


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>

这将为您提供默认选定项目的值。


推荐阅读