2014-02-25 59 views

回答

2

使用document.activeElement

document.activeElement = null; 

OR

document.activeElement && document.activeElement.blur(); 
+0

這是檢測:焦點狀態,而不是:主動統計e –

+0

它也是隻讀的,所以您不能將其設置爲null。 – devios1

5

可能的解決方案:

1)使用類:

JS:

document.getElementById("element").classList.remove("hasactive"); 

CSS:

#element.hasactive:active { 
    background:blue; 
} 

2)防止默認鼠標按下功能(工作狀態):

編輯:顯然,在Firefox這僅適用。

JS:

document.getElementById("element").onmousedown = function(event) { 
    event.preventDefault(); 
} 

3)它

HTML刪除樣式元素與CSS規則:

<style id="activestyle"> 
#element:active { 
/*Your code here*/ 
} 
</style> 

JS:

document.getElementById("activestyle").remove(); 
1

這是通過重置DOM元素的技巧。

function resetElement(e){ 
    var $e = $(e); 
    var $original = $e.clone(); 
    $e.replaceWith($original); 
} 

然後調用它:

resetElement(document.activeElement); 
+1

測試工作。 這似乎是蠻力使用JS的主動刪除的最佳答案。 –

0

jQuery的用戶:
JS:

$(".btn").click(function() { $(this).blur(); }); 

HTML:

<button type="button" class="btn btn-success">press me</button>