我似乎不知道如何将事件(动态)附加到文本框和选择框:
错误:需要对象,第 19 行
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
window.onload = function fnOnLoad() {
var t = document.getElementsByTagName('SELECT');
var i;
for (i = 0; i < t.length; i++) {
alert(t[i].id)
document.getElementById(t[i].id).attachEvent('onfocus', function () {
document.getElementById(this.id).style.backgroundColor = "#FFFF80"
})
document.getElementById(t[i].id).attachEvent('onblur', function () {
document.getElementById(this.id).style.backgroundColor = "#FFFFFF"
})
}
}
</script>
</head>
<body>
<input id="t1" type="text">
<input id="t2" type="text">
<input id="t3" type="text">
<br>
<br>
<select id="d1"></select>
<select id="d2"></select>
<select id="d3"></select>
</body>
</html>