gpt4 book ai didi

javascript - 在文本字段中显示下拉列表的选定值 (javascript)

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:37:26 24 4
gpt4 key购买 nike

例如:这些是下拉列表中的项目。

<select name="cmbitems" id="cmbitems">
<option value="price1">blue</option>
<option value="price2">green</option>
<option value="price3">red</option>
</select>

当用户选择蓝色时,我想在下面的文本字段中显示 price1 的值:

<input type="text" name="txtprice" id="txtprice" onClick="checkPrice()">

谢谢你的回答

最佳答案

您需要做的就是在 select.onchange 事件处理程序中将输入的值设置为选择的值。

var select = document.getElementById('cmbitems');
var input = document.getElementById('txtprice');
select.onchange = function() {
input.value = select.value;
}

Here是 jsFiddle 演示的链接

关于javascript - 在文本字段中显示下拉列表的选定值 (javascript),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10520328/

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