在此代码中,Firefox 将“this”视为被单击的元素,并通过正确的方式传递 href 属性。
IE 似乎认为“this”是[对象窗口]。我怎样才能让它在两个浏览器中以相同的方式工作?
注意:jQuery 会很不错,但不是这个项目的选择
var printElem = getElementsByClassName('print', 'a');
for(i in printElem){
ObserveEvent(printElem[i], 'click', function(e){
window.open(this.href, '', 'location=0,menubar=1,resizable=1,scrollbars=1,width='+810+',height='+700);
cancelEvent(e);
});
}
您可以使用事件目标 http://www.quirksmode.org/js/events_properties.html#target, 像这样:
ObserveEvent(printElem[i], 'click', function(e){
var target = e.target || e.srcElement;
window.open(target.href, '', 'location=0,menubar=1,resizable=1,scrollbars=1,width='+810+',height='+700);
cancelEvent(e);
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)