事實用以下檢測代碼來檢測時,是支持Keyup的function detectEventSupport(eventName) { var tempElement = document.createElement('div'),
isSupported;
eventName = 'on' + eventName;
isSupported = (eventName in tempElement); // 使用第一種方式
// 如果第一種方式行不通,那就來看看它是不是已知事件類型
if (!isSupported) {
tempElement.setAttribute(eventName, 'xxx');
isSupported = typeof tempElement[eventName] === 'function'; if(typeof tempElement[eventName] != 'undefined'){
tempElement.removeAttribute(eventName);
}
} // 清除掉動態創建的元素,以便內存回收
tempElement = null; // 返回檢測結果
return isSupported;
}但實際上使用時并不會觸發。因此想模擬keyup事件var mock = null;
addEvent(document, 'keydown', function(e) {
keydownHandler(e); if (mock) clearTimeout(mock);
mock = setTimeout(function() {
keyupHandler(e);
}, 200);
});但是這種方法的效果不是很好,請問還有沒有更好的方法
電視機頂盒的瀏覽器不支持keyup事件,可以如何模擬?
一只甜甜圈
2018-09-03 19:06:27