触发 onblur
属性当元素失去焦点。
没有。
<element onblur="script">
所有HTML元素,EXCEPT:
<base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, <title>
onblur |
Yes | Yes | Yes | Yes | Yes |
<!DOCTYPE html>
<html>
<body>
Enter your first name: <input type="text" name="fname" id="fname" onblur="myFunction()">
Enter your last name: <input type="text" name="lname" id="lname" onblur="myFunction()">
<script>
function myFunction() {
console.log("lost focus");
}
</script>
</body>
</html>
下面的代码显示了如何听输入密码的Focus Lost事件。
<html>
<head>
<script type="text/javascript">
function checkRequired() {
document.write("value is required in field");
}
</script>
</head>
<body>
<form name="someForm">
<input type="text" name="text1" /><br />
<input type="password" name="text2" onblur="checkRequired();"/><br />
<input type="hidden" name="text3" value="hidden value" />
<textarea name="text4" cols=50 rows=10>The text area</textarea>
<input type="submit" value="Submit" />
</form>
</body>
</html>