我知道这很简单,但我尝试了很多解决方案但都失败了。我有一个使用 <select>
的表格在 <option>
中标记我使用两个值 coo
和 uh
我希望当用户选择 uh 然后它显示一个额外的 input type
field 。
这是我的代码。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script>
<script>
$('#s_designation').on('change',function(){
if ($(this).val() === "uh") {
$("#uh").show()
}
else {
$("#uh").hide()
}
});
</script>
<title>Untitled Document</title>
</head>
<body>
<label for="db">Choose type</label>
<select name="s_designation" id="s_designation">
<option value="coo">Chief Operating Officer</option>
<option value="uh">Unit Head</option>
</select>
<div id="uh" style="display:none;">
<label for="specify">Specify</label>
<input type="text" name="specify" placeholder="Specify Designation"/>
</div>
</body>
</html>
最佳答案
我刚刚测试了你的代码,它工作正常:
链接:
https://jsfiddle.net/g95pyqw6/
编辑:但这可能是因为 JSfiddle。 尝试取消注释 Javascript 的第一行,这应该会有所帮助! :-)
希望能帮到你。如果您需要更多帮助,请随时发表评论:-)
关于javascript - 如何在选择中显示输入类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31938729/