<script>
var obj = document.getElementsByName('user')[0]
var os = document.createElement('span')
var sp=document.body.insertBefore(os,obj)
obj.onblur = function(){
sp.innerText='合法'
alert(111)
}
</script>
=======================================event来判断当前对象.如果非特定元素,执行onblur
快采纳啊!亲测可用。
=======================================
<div id='list' onmousemove="c()">
<form method='post' action='' id='form'>
<dl >
<dd>
请填写权限名称:
<input type='text' name='pername' id='pername'/><span class='must'>
</dd>
<dd>
<input type='submit' class='submit' value='提交'id='submit'/>
</dd>
</form>
</dl>
</div>
<script type='text/javascript'>
var cur
window.onload=function (){
var fm=document.getElementById('form')
var pername=document.getElementById('pername')
fm.onsubmit=check_submit
pername.onblur=function (){
if(cur!="submit")
alert('pername失去焦点')
}
}
function check_submit (){
alert('提交l')
}
function c()
{
cur=event.target.type
}
</script>
object.blur()这样就可以了. 但不是所有对象都有blur方法的, 具体可以参考DOM手册.
button和 input type="button" 都有 blur 方法.