如何实现选择下拉列表值时,在右边的文本框里显示所选中的值。
<form><selectname="cars"><optionvalue="volvo">Volvo</option><optionvalue="saab">Saab<...
<form>
<select name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
<input type="text" name="name">
</form> 展开
<select name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
<input type="text" name="name">
</form> 展开
1个回答
展开全部
<form>
<select name="cars" id="cars" onchange="shows();">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
<input type="text" name="name" id="name">
</form>
<script>
function shows()
{
if(document.getElementById('cars').value!=""&&document.getElementById('cars').value!=null)
{
document.getElementById('name').value=document.getElementById('cars').value;
}
}
</script>
<select name="cars" id="cars" onchange="shows();">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
<input type="text" name="name" id="name">
</form>
<script>
function shows()
{
if(document.getElementById('cars').value!=""&&document.getElementById('cars').value!=null)
{
document.getElementById('name').value=document.getElementById('cars').value;
}
}
</script>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询