2017-09-15 56 views
0

我無法獲取在Firefox(55)上觸發的指示燈事件,但在Chrome(60)上也可以正常工作,例如,如何讓指針事件在Firefox上運行?

<!DOCTYPE html> 
<html> 
<body> 
<p>Click or tap anywhere in the document.</p> 
<p id="demo"></p> 
<script> 
    document.addEventListener("pointerdown", function() { 
     console.log("pointerdown fired"); 
     document.getElementById("demo").innerHTML += "Hello World! "; 
    }); 
</script> 
</body> 
</html> 

在Firefox中,使用鼠標或觸控設備時,不會觸發指示燈事件。在Chrome中,同樣的事情可以正常工作。

請參閱fiddle

+1

嘗試'mousedown'而不是'pointerdown' – prasanth

+0

我不想使用mousedown,因爲我希望在觸摸和桌面設備上都能使用通用事件。爲此目的創建了指針,所以你不必註冊mousedown和touchstart等,而是一個事件。 –

+1

你是對的,但許多瀏覽器不支持event.https://developer.mozilla.org/en-US/docs/Web/Events/pointerdown請看支持。並且還可以參考指針的一般信息 – prasanth

回答

0

看起來指針事件在Firefox中默認不會啓用。有關詳細信息,請參閱Bugzilla上的this。 要打開指針事件,導航到about:config中,搜索dom.w3c_pointer_events.enabled,然後點擊鼠標右鍵,將值切換至真正

相關問題