onblur與onbeforedeactivate的區別

前者在切換到window的其它程序時會激發,後面不會;光標落到另外一個元素後,前者先產生另外一個元素的onfocus事件,再產生本元素的onblur事件,後者則是先本元素的onbeforedeactivate事件,若是返回true後,而後再另外一個元素的onfocus事件,若是返回false,則不會激發另外一個元素的事件(?鼠標右鍵除外,而且此時另外一元素的onfocus對鼠標右鍵也感冒);
用onbeforedeactivate能夠解決搶焦點的死循環
<input type="text" onblur="alert('OK1');event.srcElement.select();return false;" />
<input type="text" onblur="alert('OK2');event.srcElement.focus();return false;" />
這樣會產生死循環,而如下代碼則不會
<input type="text" onbeforedeactivate="alert('OK1');event.srcElement.select();return false;" />
<input type="text" onbeforedeactivate="alert('OK2');event.srcElement.focus();return false;" />spa

相關文章
相關標籤/搜索