我有一个文本区域
<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);
}
这就是我填充组合框之一的方式
答案 0 :(得分:1)
您可以使用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>
希望对您有帮助。