window屬性:onblur

2018-04-24 10:43 更新

onblur屬性

該onblur屬性表示該blur事件的對象的事件處理程序。它能夠在Element,Document和Window中使用。

onblur屬性語法

element.onblur = function;
  • function是用戶定義的函數(shù)的名稱,不帶()后綴或任何參數(shù)或匿名函數(shù)聲明,如下所示:
    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

公眾號
微信公眾號

編程獅公眾號