这几天在在学习javasceipt的内容,在用addEventListener添加focus事件和blur事件出现问题,
网上找了好久才找到解决方案,所以记录一下
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<input type="password" id="aaaaa" placeholder="focus和biur测试" required="">
<script>
document.getElementById("aaaaa").addEventListener("focus", myFunctiona,true);
document.getElementById("aaaaa").addEventListener("blur", myFunctionb,true);
function myFunctiona()
{
document.getElementById("aaaaa").style.background="yellow";
}
function myFunctionb()
{
document.getElementById("aaaaa").style.background="red";
}
</script>
</body>
</html>