如何修改下面的代码,以便将onblur
andonfocus
应用于文本框和选择框?现在它只适用于文本框,我似乎无法让它应用于选择框。
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
window.onload =
function fnOnLoad() {
var t = document.getElementsByTagName('INPUT');
var i;
for(i=0;i<t.length;i++)
{
//alert(t[i].type)
if(t[i].type == "text")
{
t[i].attachEvent('onfocus', new Function("fnTXTFocus('"+t[i].id+ "')"));
t[i].attachEvent('onblur', new Function("fnTXTLostFocus('"+t[i].id+ "')"));
}
}
}
function fnTXTFocus(varname) {
var objTXT = document.getElementById(varname)
objTXT.style.backgroundColor = "#FFFF80";
}
function fnTXTLostFocus(varname)
{
var objTXT = document.getElementById(varname)
objTXT.style.backgroundColor = "#FFFFFF";
}
</script>
</head>
<body>
<input id="t1" type="text" >
<input id="t2" type="text" >
<input id="t3" type="text" >
<br><br>
<select size="d1" ></select>
<select size="d2" ></select>
<select size="d3" ></select>
<p>When the input field gets focus,
a function is triggered which changes the background-color.</p>
</body>
</html>