我正在使用以下代码覆盖名为dismissRelatedLookupPopup()的JavaScript函数。在Firefox中,这可以正常工作(一次显示警报并运行我的代码),但是在Internet Explorer 7中,它会导致无限循环,永远显示alert()。我这样做是因为我无法控制调用dismissRelatedLookupPopup()的代码,而且我想在调用时添加一个自己的钩子。有跨浏览器的方法吗?
old_dismissRelatedLookupPopup = dismissRelatedLookupPopup;
dismissRelatedLookupPopup = function dismissRelatedLookupPopup(win, chosenId) {
alert("i hate ie");
old_dismissRelatedLookupPopup(win,chosenId);
var name = windowname_to_id(win.name);
var elem = document.getElementById(name);
elem.onchange();
}
注意:据我了解,当JavaScript直接更新元素的值(即elem.value = 1)时,该元素的onchange()事件将不会触发。这就是为什么我包含此代码以在值更新时强制onchange()的原因。
最佳答案
我很确定要更改此行:
dismissRelatedLookupPopup = function dismissRelatedLookupPopup(win, chosenId)
至
dismissRelatedLookupPopup = function (win, chosenId)
将治愈什么病呀。