问题描述
问题描述:在ie下层级广告div中能动态添加链接,并通过点击链接,能关闭层级div。在firefox下层级广告div能显示,但动态添加的链接没显示出来,不知道是没添加上还是显示的原因。附件中的图片分别为ie下和firefox下的显示效果。在此先谢过。代码如下:<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Insert title here</title><style type="text/css">.layerad{position:absolute;width:200px;height:100px;left:1em;top:1em;border:1px solid black;}</style><script type="text/javascript">function addEvent(elm, evType, fn, useCapture){if (elm.addEventListener){elm.addEventListener(evType, fn, useCapture);return true;} else if (elm.attachEvent) {var r = elm.attachEvent('on' + evType, fn);return r;} else {elm['on' + evType] = fn;}}//设置层级广告function setLayerAd(){var ad = document.getElementById('ad');//设为层级显示ad.className = 'layerad';var a = document.createElement('A');a.setAttribute('href','#');a.innerText = 'close';addEvent(a,'click',function(){ad.style.display = 'none';},false);//ad.insertBefore(a,ad.firstChild);ad.appendChild(a);}addEvent(window,'load',setLayerAd,false);</script></head><body><div id="ad">深入浅出javascript</div></body></html>
解决方案
firefox 不支持innerText 改为innerHTML