網站搜尋

javascript - 事件在 IE 中未定義,但在 Firefox 中可用


我在文字方塊中有 onKeypress 事件,這在 FireFox 中有效,但在 IE 中無效

在 IE 中事件被傳遞為未定義

PriceInBox.onkeypress = function(event) { return moZoltarCurrent.evt_checkForInt(event); }

答案#1

你需要正規化 Event 介面,因為 IE 不會作為參數傳遞它,而是使用全域變數:

PriceInBox.onkeypress = function(event) {
    event = event || window.event;
    return moZoltarCurrent.evt_checkForInt(event);
};