小编use*_*131的帖子

Javascript IE错误:'target'为null或不是对象

document.onkeydown = function(event) {
    var tagName = event.target.tagName;
    if (tagName != 'INPUT' && tagName != 'TEXTAREA' && !event.alt && event.control) {

        if (event.ctrlKey && event.keyCode == 37) {
            if (_this.currentPage > 1) {
                window.location.href = _this.baseUrl.replace(/%page%/i, _this.currentPage + 1);
            }
        } else if (event.ctrlKey && event.keyCode == 39) {
            if (_this.currentPage < _this.pagesTotal) {
                window.location.href = _this.baseUrl.replace(/%page%/i, _this.currentPage - 1);
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这只在IE 8中出现错误:

'target'为null或不是对象

为那条线 var tagName = event.target.tagName;

如何解决这个问题.按Ctrl或箭头按钮时发生错误.

javascript internet-explorer javascript-events

3
推荐指数
1
解决办法
6918
查看次数