您好,感谢您提前帮助。请注意,我是新手,这可能解释了为什么我无法弄清楚这个问题。
我想在下拉列表的值更改时动态更改输入文本字段的值。
我的页面负责人:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<link rel="stylesheet" type="text/css" href="mystyle.css" />
<script type="text/javascript" src="projectJS.js"></script>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
// initialize the value of the input field to the selected value
// of the dropdown list:
$("#membfee").val($("#role").val());
$("#role").click(function() {
// when the value of the dropdown list changes
// update the input field
$("#membfee").val("111");
});
});
</script>
</head>
我不知道jquery有任何问题,这一切都非常简单。你能像我上面那样引用外部javascript文件和jquery吗?
包含我想要更新的下拉菜单和文本字段的正文部分:
<tr>
<td class="label_block">Membership Term:</td>
<td> <select name="role" id="role" />
<option value="Trial">Trial</option>
<option value="1 Month">1 Month</option>
<option value="3 Month">3 Month</option>
<option value="6 Month">6 Month</option>
<option value="Year">Year</option>
</select>
</td>
</tr>
<tr>
<td class ="label_block">Membership Fee:</td>
<td><input type="text" size="15" name="membfee" id="membfee" value="" /></td>
<td class="error">
<%out.print(membfee_msg);%>
</td>
</tr>
答案 0 :(得分:2)
您应该使用.change()
:
$("#role").change(function() {
// when the value of the dropdown list changes
// update the input field
$("#membfee").val("111");
});
您确定页面上没有任何JS错误,因为它just should work。
答案 1 :(得分:1)
请尝试使用change()
事件:
$("#role").change(function(){
// blabla
})