所以这一直让我发疯,我正在寻找一种解决方案,该解决方案将根据下拉列表中的任何选择来填充输入字段。
我目前的工作解决方案(不包括下拉列表)如下:
<form method="link" action="dualstream/index.html">
<input value = 'apolloz' name="stream1" placeholder="" required="required"
autofocus="autofocus" />
<input type="submit" class="button" value="Click to watch the stream" />
</form>
这样自动用“apolloz”填充文本字段,然后当您按下提交时,它会将您带到使用单词 apolloz 的相关页面。
我正在寻找一种解决方案,您可以从下拉列表中选择流媒体,选择它,然后该选项填充文本字段,然后您就可以提交了。
我确定这是基于 javascript 的,因为我见过类似的使用数值的东西。
抱歉,如果这有点含糊,但非常感谢任何和所有帮助。
最佳答案
试试这个
<form method="link" action="dualstream/index.html">
<input value = 'apolloz' id="txt" name="stream1" placeholder="" required="required"
autofocus="autofocus" />
<select id="mySelect" onchange="selectionchange();">
<option value="abc" >abc</option>
<option value="xyz" >xyz</option>
</select>
<input type="submit" class="button" value="Click to watch the stream" />
</form>
并添加以下javascript函数
function selectionchange()
{
var e = document.getElementById("mySelect");
var str = e.options[e.selectedIndex].value;
document.getElementById('txt').value = str;
}
关于javascript - 如何从下拉列表中填写输入字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20091656/