网页select选择框根据所选条目录改变文本框内容
发布网友
发布时间:2022-04-19 07:17
我来回答
共1个回答
热心网友
时间:2022-04-19 08:47
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">
<head>
<title>自动选择文本</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<script type="text/javascript">
function fun() {
var goods=document.getElementsByName("goods");
for (var i=0,len=goods.length;i<len;i++) {
goods[i].onclick = fun1;
}
}
function fun1() {
document.getElementsByName('ku1')[0].value = this.value;
document.getElementsByName('ku2')[0].value = this.value;
}
</script>
<style type="text/css">
</style>
</head>
<body onload="fun();">
<p>
<select>
<option name="goods" value="商品">商品</option>
<option name="goods" value="香烟">香烟</option>
<option name="goods" value="啤酒">啤酒</option>
<option name="goods" value="大米">大米</option>
<option name="goods" value="生葱">生葱</option>
<option name="goods" value="奶粉">奶粉</option>
</select>
</p>
<p><input name="ku1" type="text"/></p>
<p><input name="ku2" type="text"/></p>
</body>
</html>