HTML事件属性onblur

2018-01-05 13:58 更新

HTML事件属性onblur


触发 onblur 属性当元素失去焦点。

HTML5中的新功能

没有。

句法

<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>

Click to view the demo



实施例2

下面的代码显示了如何听输入密码的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>

Click to view the demo

以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号