我有一个下拉菜单,其中有其他选项,当选择其他选项时,会出现一个新字段,我们可以在其中输入指定其他的文本,但是当填充文本时,我无法在该字段中填充数据,我只能得到其他
HTML:
<html>
<head>
<script type="text/javascript">
function showfield(name){
if(name=='Other')document.getElementById('div1').innerHTML='Other: <input type="text" name="other" />';
else document.getElementById('div1').innerHTML='';
}
</script>
</head>
<body>
<select name="drop" id="drop" onchange="showfield(this.options[this.selectedIndex].value)">
<option selected="selected">Please select ...</option>
<option value="car">car</option>
<option value="bike">bike</option>
<option value="Other">Other</option>
</select>
<div id="div1"></div>
</body>
</html>
以及如何放置帮助文本,当我们在选择其他文本框时将数据插入到新文本框中时,该帮助文本将会消失。
提前致谢。
最佳答案
试试这个,它对你有用
<html>
<head>
<script type="text/javascript">
function showfield(name){
var name=document.getElementById("drop").value;
if(name=='Other'){
document.getElementById('div1').innerHTML='Other: <input type="text" name="other" />';
}
else {
document.getElementById('div1').innerHTML='';
}
}
</script>
</head>
<body>
<select name="drop" id="drop" onchange="showfield()">
<option selected="selected">Please select ...</option>
<option value="car">car</option>
<option value="bike">bike</option>
<option value="Other">Other</option>
</select>
<div id="div1"></div>
</body>
</html>
关于javascript - 下拉字段中插入的文本未反射(reflect),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35739427/