且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-02-11 20:04:27

您需要做的就是在 select.onchange 事件处理程序中将 input 的值设置为 select 的值.

All you need to do is set the value of the input to the value of the select, in a select.onchange event handler.

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

这里是 jsFiddle 演示的链接

Here is a link to a jsFiddle demo