【发布时间】:2015-08-11 19:03:55
【问题描述】:
我知道这很简单,但我尝试了很多解决方案,但都失败了。我有一个表单,我在<option> 中使用<select> 标记我使用两个值coo 和uh 我希望当用户选择时它会显示一个额外的input type 字段。
这是我的代码。
<!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>
【问题讨论】:
-
到底是什么失败了?
-
当我点击
uh时,我的代码没有显示我的额外输入字段 -
尝试将代码放入
$(document).ready()。 jsfiddle.net/rejithrkrishnan/f4pu6uce 看起来不错。 -
您的代码运行良好,请在此处查看:jsfiddle.net/m5n6v8as
-
@RejithRKrishnan 它不适用于 my.php 文件
标签: javascript jquery html css ajax