电视机顶盒的浏览器不支持keyup事件,可以如何模拟?

事实用以下检测代码来检测时,是支持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);
});

但是这种方法的效果不是很好,请问还有没有更好的方法

阅读 3.8k
4 个回答

电视用什么浏览器啊?

还有基于电视终端开发的?!!!

厉害了我的哥!
alert 一下 navigator.userAgent 看看什么内核的呀

用touchend事件代替

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题