下面的函数在 IE 9 及更高版本中工作正常,但文本不会出现在 IE 8 及更低版本中。
html:
<body onLoad="BuildBrwsrInfoMsg();" style="background: url('../images/BeachBackground.jpg'); margin-top:0; " id="LoadingDisplay" >
脚本:
function BuildBrwsrInfoMsg()
{
var maindiv = document.getElementById('Background-Header');
var div = document.createElement('div');
div.setAttribute('id', 'browserInfo');
var spanBrwsrNameVersion = document.createElement('span');
spanBrwsrNameVersion.textContent = "Browser Not Supported - You are using ("+ bowser.name + ' ' + bowser.version + ")";
spanBrwsrNameVersion.setAttribute('class', 'BrowersTitle' );
div.appendChild(spanBrwsrNameVersion);
var spanBrwsrMsg = document.createElement('span');
spanBrwsrMsg.textContent = "This browser may not be compatible with our website. For best results, it is suggested that you upgrade to the latest version. To download the latest version Click";
spanBrwsrMsg.setAttribute('class', 'BrowersDescription' );
div.appendChild(spanBrwsrMsg);
var hideBtn = document.createElement('input');
hideBtn.setAttribute('id', 'btnHideMsg');
hideBtn.setAttribute('type', 'submit');
hideBtn.setAttribute('value', 'Hide Message');
div.appendChild(hideBtn);
maindiv.insertBefore(div, maindiv.firstChild);
}
最佳答案
这都是关于 IE < 9 不支持 textContent
属性。official documentations about the textContent property 上已证实这一点。 .
关于javascript - 文字不会出现在 IE8 及更低版本中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23281006/