можно это как то упростить?))
<!DOCTYPE html>
<html>
<head>
<title>test</title>
<style>
div {
width: 100px;
height: 100px;
border: 1px solid black;
}
</style>
</head>
<body>
<input type="text" onblur="b(event)" onfocus="f(event)">
<div style="display: none;"></div>
<script>
var div = document.querySelector('div'),
input = document.querySelector('input');
function f(e) {
div.style.display = 'block';
}
function b(e) {
console.log(lastKeyDown);
if (lastKeyDown == 9) {
div.style.display = 'none';
}
}
var lastKeyDown = null;
window.onkeydown = function (e) {
lastKeyDown = e.keyCode;
}
window.onclick = function (e) {
if (e.target != div && e.target != input) {
div.style.display = 'none';
}
}
</script>
</body>
</html>