自己再按自己要求改改吧。
代码如下:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<select id="s">
<option x=1 y=2>新租</option>
<option x=3 y=4>新买</option>
<option x=5 y=6>折旧</option>
</select>
<input id="x" type="" name="">
<input id="y" type="" name="">
</body>
<script>
document.getElementById('s').onchange=function(){
x=this.options[this.selectedIndex].getAttribute('x');
y=this.options[this.selectedIndex].getAttribute('y');
document.getElementById('x').value=x;
document.getElementById('y').value=y;
}
</script>
</html>
追问当页面加载时这个select框没有,后来点击页面按钮有了这个select ,这就导致一开始页面加载时ID为空这怎么办?
追答