日期:2014-05-16  浏览次数:20339 次

javascript 有没有办法判断一个button是否获取了焦点
javascript   有没有办法判断一个button是否获取了焦点

------解决方案--------------------
被动方式
var focus_btn = null;

button onfocus event
focus_btn = this;
------解决方案--------------------
<button id= "button1 " isFocused= "false " onfcus= "this.isFocused= 'true '; " onblur= "this.isFocused= 'false '; "> 按扭 </button>

<script>
//这样取得
var s = document.getElementById( 'button1 ').getAttribute( 'isFocused ');
<script>
------解决方案--------------------
给加个失去焦点的事件,然后让别的某个控件获得焦点,如果这时候那个事件发生了,那么表明该控件之前是有获得焦点的~~~~~
------解决方案--------------------
alert(document.activeElement == button对象); ie only

方法二,button.addEventLintener( 'focus ', function () { alert( "获取到焦点的说 ") }, false);