我需要以下代码的一些帮助,我想设置已经选择到textarea但我不想等同/返回值属性但是叙述。对于下面的情况,textarea的价值 1 ,我希望它能得到叙述第一行
var myOption = document.getElementById('priority1');
var myStrategy = document.getElementById('strategy1');
myStrategy.onchange = function () {
myOption.value = this.value;
}

<textarea id="priority1" name="priority1"></textarea>
<select id="strategy1" name="strategy1">
<option value=""></option>
<option value="1">Line one</option>
<option value="2">Line Two</option>
<option value="3">Line Three</option>
</select>
&#13;
答案 0 :(得分:4)
您需要找到selectedIndex
option
的文字内容(或HTML内容)。
<textarea id="priority1" name="priority1"></textarea>
<select id="strategy1" name="strategy1">
<option value=""></option>
<option value="1">Line one</option>
<option value="2">Line Two</option>
<option value="3">Line Three</option>
</select>
<script type="text/javascript">
var myOption = document.getElementById('priority1');
var myStrategy = document.getElementById('strategy1');
myStrategy.onchange = function() {
myOption.value = this.querySelectorAll('option')[this.selectedIndex].innerHTML;
}
</script>
&#13;
答案 1 :(得分:0)
您可以按索引this.options[this.selectedIndex]
获取所选选项,然后使用.text
而不是值来获取选项文字:
myStrategy.onchange = function () {
myOption.value = this.options[this.selectedIndex].text
}
这会有所帮助。
var myOption = document.getElementById('priority1');
var myStrategy = document.getElementById('strategy1');
myStrategy.onchange = function () {
myOption.value = this.options[this.selectedIndex].text
}
<select id="strategy1" name="strategy1">
<option value=""></option>
<option value="1">Line one</option>
<option value="2">Line Two</option>
<option value="3">Line Three</option>
</select>
<br><br>
<textarea id="priority1" name="priority1"></textarea>
答案 2 :(得分:0)
您可以更改每个选项的git rebase -i
value
&#13;