鍍金池/ 問答/HTML/ 在非標準ie8下,關于setCapture的使用不理解,在元素上設置了之后只能捕

在非標準ie8下,關于setCapture的使用不理解,在元素上設置了之后只能捕獲一次嗎?

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>無標題文檔</title>
<script>
window.onload = function() {
    
    var aInput = document.getElementsByTagName('input');
    
    aInput[0].setCapture();    
    aInput[0].onclick = function() {//問題1
        console.log(1);
        //alert(1);
    }
aInput[0].onmouseleave = function() {
        console.log(3);
    }
    
    aInput[1].onclick = function() {
        alert(2);
    }
    
}
</script>
</head>

<body>
    <input type="button" value="按鈕一" />
    <input type="button" value="按鈕二" />
</body>
</html>

問題1:在執(zhí)行aInput[0].onclick全局捕獲之后aInput[0].onmouseleave沒有執(zhí)行全局捕獲
問題2:在執(zhí)行aInput[0].onclick全局捕獲之后;再次執(zhí)行aInput[0].onclick沒有執(zhí)行全局捕獲
問題3:關于setCapture的使用不理解,在元素上設置了之后只能捕獲一次嗎?
如果只能捕獲一次,那releaseCapture 就沒有意義了?

回答
編輯回答
念初

setCapturereleaseCapture 這兩個函數(shù)很像是 Windows 下的函數(shù)(因為桌面應用開發(fā)里有),所以去查了一下,果然,說是基于 IE 實現(xiàn),沒說有哪些瀏覽器兼容該實現(xiàn)。

然后 setCapture 文檔的第一段就說明了,捕捉狀態(tài)在松開按鈕或 releaseCapture 的時候結束

Call this method during the handling of a mousedown event to retarget all mouse events to this element until the mouse button is released or document.releaseCapture() is called.

2017年9月19日 03:06