onBlur事件:onBlur事件是当光标离开文本框中时发生的事件。
onfocus事件:onfocus事件在对象获得焦点时发生的事件。
例子:
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<script type=”text/javascript”>
//获得焦点输入背景设置为黄色
function setStyle(x)
{
document.getElementByIdx_x(x).style.background=”yellow”
}
//失去焦点输入背景重置为白色
function recoveryStyle(y)
{
document.getElementByIdx_x(y).style.background=”White”
}
</script>
</head>
<body>
First Name: <input type=”text”
οnfοcus=”setStyle(this.id)” id=”fname” onBlur=”recoveryStyle(this.id)” />
<br />
Last Name: <input type=”text”
οnfοcus=”setStyle(this.id)” id=”lname” onBlur=”recoveryStyle(this.id)”/>
</body>
</html>