自己再按自己要求改改吧。
代码如下:
<!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为空这怎么办?
追答![](https://video.ask-data.xyz/img.php?b=https://iknow-pic.cdn.bcebos.com/b3119313b07eca800fd1fc6b9c2397dda0448362?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_600%2Ch_800%2Climit_1%2Fquality%2Cq_85%2Fformat%2Cf_auto)