window属性:onblur

onblur属性

该onblur属性表示该blur事件的对象的事件处理程序。它能够在Element,Document和Window中使用。

onblur属性语法

element.onblur = function;
  • function是用户定义的函数的名称,不带()后缀或任何参数或匿名函数声明,如下所示:
    element.onblur = function(){console.log(“onblur event detected!”); };

onblur属性示例

<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';
  console.log("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>
以上内容是否对您有帮助:

您可能还喜欢:

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部