当用户从我的下拉菜单中选择选项时,我正在尝试动态更改输入字段值。我试过这段代码,但没有运气。我想知道这里是否有人可以帮助我!非常感谢。
$(document).ready(function(){
$('select[name="job_number"]').change (function () {
$('input[name="project"]').val()="Good Fish";
});
});
<form action='project_manager' method='post'>
<input type='text' name='project'>show Good Fish when user picks an option</input>
<select name='job_number'>
<option value='1'>job1</option>
<option value='2'>job2</option>
<option value='3'>job3</option>
</select>
</form>
答案 0 :(得分:65)
尝试:
$('input[name="project"]').val("Good Fish");
而不是:
$('input[name="project"]').val()="Good Fish";
答案 1 :(得分:14)
以下代码应该有效。我修改了html中的<input>
以正确格式化,并将$('input[name="project"]').val()="Good Fish";
更改为$('input[name="project"]').val("Good Fish");
$(document).ready(function(){
$('select[name="job_number"]').change(function() {
$('input[name="project"]').val("Good Fish");
});
});
<form action='project_manager' method='post'>
<input type='text' name='project' value='show Good Fish when user picks an option' />
<select name='job_number'>
<option value='1'>job1</option>
<option value='2'>job2</option>
<option value='3'>job3</option>
</select>
</form>