gpt4 book ai didi

javascript:表单选择选项和输入字段

转载 作者:行者123 更新时间:2023-11-29 10:20:30 25 4
gpt4 key购买 nike

我有一个表单 input 字段,当用户键入“text 2”时,我希望在 select 表单中选择“text 2”:

<select id="formsel">
<option value="text 1">text 1</option>
<option value="text 3">text 2</option>
<option value="text 3">text 3</option>
</select>
<input type='text' id='input' />

我从 input 中获取值,如下所示:

var input_val = document.getElementById('input').value; 

但我无法从动态表单中选择选项 select with

document.form.formsel.value = input_val;

谁能看出我做错了什么?

最佳答案

您的代码未显示您尝试使用 document.form 访问的 form,因此我假设没有表单。尝试通过其 ID 访问 select。这似乎对我有用:

<script>
document.getElementById('input').onkeyup = function()
{
var input_val = document.getElementById('input').value;
document.getElementById('formsel').value = input_val;
}
</script>

关于javascript:表单选择选项和输入字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13180537/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com