我的目标是让文本字段中的文本输入替换选择/选项下拉列表中的通用选项。我现在所做的不起作用,并显示为未定义。 这是我的标记:(请包含一个普通的 javascript 选项) HTML:
<input id="name1" type="text" placeholder="name here" onKeyUp="return change1(this)">
<input id="name2" type="text" placeholder="name here" onKeyUp="return change2(this)">
等等
<h4>Choose person:</h4>
<select id="select1">
<option id="pers1" value="1">person</option>
<option id="pers2" value="2">person</option>
..还有其中几个
Javascript:
function change1(input){
document.getElementById("pers1").text =
input.text; }
function change2(input){
document.getElementById("pers2").text =
input.text; }
等等
最佳答案
<script>
function change1(input){
document.getElementById("pers1").text = input.value;
}
function change2(input){
document.getElementById("pers2").text = input.value;
}
</script>
<h4>Choose person:</h4>
<select id="select1">
<option id="pers1" value="1">person</option>
<option id="pers2" value="2">person</option>
</select>
<hr>
<input id="name1" type="text" placeholder="name here" onKeyUp="change1(this)">
<input id="name2" type="text" placeholder="name here" onKeyUp="change2(this)">
关于javascript - 通过上面的输入更改选择/选项通用文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20931296/