[英]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.