<!DOCTYPE html>
<html>
<head>
<script>
function myFunction(x)
{
x.style.backgroundColor="red";
}
function disFuction(x){
x.style.backgroundColor="white";
}
</script>
</head>
<body>
请输入英文字符:<input type="text" onmouseover="myFunction(this)" onmouseout="disFuction(this)">
<p>当光标移动到输入框时候,会触发改变背景颜色的函数。当光标移开输入框时候,会触发改变背景颜色的函数。</p><br><br><br>
请输入英文字符:<input type="text" onfocus="myFunction(this)" onblur="disFuction(this)">
<p>当输入字段获得焦点时,会触发改变背景颜色。当失去焦点时,会触发改变背景颜色。</p><br><br><br>
</body>
</html>
JavaScript触发函数onmouseover,onmouseout,onfocus,onblur综合实例
最新推荐文章于 2023-03-07 14:30:09 发布