繁体   English   中英

从组合框发送值到textarea

[英]send value from combobox to textarea

我有一个文本区域

<textarea id="tarea" class="textarea" cols="15" rows="10" disabled></textarea>

我想将组合框中的值发送到textarea

<div class="form-group col-xl-7">

    <label>Livro</label>
    <div id="combo">

        <select id="comboLivros">
            <option class="option"></option>
        </select>

    </div>

    <br>

    <label>Proprietário a que se refere</label>
    <input type="text" id='prop_desc' disabled/>

    <br>

    <label>Pontuação</label>
    <select  id="seleciona">

    </select>
</div>

这些是我的组合框,里面充满了数组

当我选择带有单击按钮时选择的值的组合框时,我想要填充文本区域,这就是我填充其中一个组合框的方式

var select = document.getElementById("seleciona");
var options = ["1", "2", "3", "4", "5"];
for (var i = 0; i < options.length; i++) {
    var opt = options[i];
    var el = document.createElement("option");
    el.textContent = opt;
    el.value = opt;
    select.appendChild(el);
}

这就是我填充我的组合框之一的方式

您可以使用select的事件更改来设置textarea的值:

 var select = document.getElementById("seleciona"); var options = ["1", "2", "3", "4", "5"]; for (var i = 0; i < options.length; i++) { var opt = options[i]; var el = document.createElement("option"); el.textContent = opt; el.value = opt; select.appendChild(el); } var textarea = document.getElementById("tarea"); select.onchange = function(){ textarea.value = select.options[select.selectedIndex].value; } 
 <textarea id="tarea" class="textarea" cols="15" rows="10" disabled></textarea> <div class="form-group col-xl-7"> <label>Livro</label> <div id="combo"> <select id="comboLivros"> <option class="option"></option> </select> </div> <br> <label>Proprietário a que se refere</label> <input type="text" id='prop_desc' disabled/> <br> <label>Pontuação</label> <select id="seleciona"> </select> </div> 

希望对您有帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM