onblur 事件

定义和用法

onblur 事件会在对象失去焦点时发生。

语法

onblur="SomeJavaScriptCode"
参数 描述
SomeJavaScriptCode 必需。规定该事件发生时执行的 JavaScript。

支持该事件的 HTML 标签:

<a>, <acronym>, <address>, <area>, <b>, <bdo>, <big>, <blockquote>, 

<button>, <caption>, <cite>, <dd>, <del>, <dfn>, <div>, <dl>, <dt>, 

<em>, <fieldset>, <form>, <frame>, <frameset>, <h1> to <h6>, <hr>, <i>, 

<iframe>, <img>, <input>, <ins>, <kbd>, <label>, <legend>, <li>, 

<object>, <ol>, <p>, <pre>, <q>, <samp>, <select>, <small>, <span>, 

<strong>, <sub>, <sup>, <table>, <tbody>, <td>, <textarea>, <tfoot>, 

<th>, <thead>, <tr>, <tt>, <ul>, <var>

支持该事件的 JavaScript 对象:

button, checkbox, fileUpload, layer, frame, password, 

radio, reset, submit, text, textarea, window

实例 1

在本例中,我们将在用户离开输入框时执行 JavaScript 代码:

<html>

<head>

<script type="text/javascript">

function upperCase()

{

var x=document.getElementById("fname").value

document.getElementById("fname").value=x.toUpperCase()

}

</script>

</head>



<body>



输入您的姓名:

<input type="text" id="fname" onblur="upperCase()" />



</body>

</html>

输出:

输入您的姓名: 

TIY

onblur
如何使用 onblur 事件在用户离开输入框时执行 JavaScript 代码
出自: http://www.w3school.com.cn/htmldom/event_onblur.asp

你可能感兴趣的:(blur)