Mozilla.com

  1. MDC
  2. 首页
  3. DOM
  4. element.onblur

« Gecko DOM 参考

Summary

onblur属性返回onBlur事件句柄的代码,如果它存在于当前元素的话。

Syntax

element.onblur = function;
  • function 是用户自定义函数的名称, 没有 () 后缀或者任何参数, 或者像这样的匿名函数声明
element.onblur = function() { alert("onblur event detected!"); };

Example

<html>

<head>
<title>onblur event example</title>

<script type="text/javascript">

var elem = null;

function initElement()
 {
 elem = document.getElementById("foo");
 // NOTE: doEvent(); or doEvent(param); will NOT work here.
 // Must be a reference to a function name, not a function call.
 elem.onblur = doEvent;
 };

function doEvent()
 {
 elem.value = 'Bye-Bye';
 alert("onblur Event detected!")
 }
</script>

<style type="text/css">
<!--
#foo {
border: solid blue 2px;
}
-->
</style>
</head>

<body onload="initElement()";>
<form>
<input type="text" id="foo" value="Hello!" />
</form>

<p>Click on the above element to give it focus, then click outside the
element.<br /> Reload the page from the NavBar.</p>

</body>
</html>

Notes

blur事件在一个元素失去焦点的时候被触发。

相对于MSIE,几乎所有类型的元素都接收blur事件,在gecko浏览器中的大部分元素都无法令该事件正常工作。

Specification

DOM Level 0. Not part of specification.

Page last modified 12:44, 9 Apr 2007 by Bingdian3721?

文件 (0)