我正在使用JavaScript覆盖我的网站第三方购物车中的一些预设选项。 该脚本在Chrome和Firefox中完美运行,但它根本无法在Internet Explorer中使用。
我的脚本是<script src="http://www.amorame.com/geoff.js"></script>;
alert('test');
function x(){
var y=document.forms[0].elements["pm"];
var z;
for (var j=0; j<y.length; j++) {
z=y[j];
if (z.value=="40") {
z.style.display="none";
}
}
document.body.innerHTML=document.body.innerHTML.replace("Payment by <b>Moneybookers</b> e-wallet<br>","");
document.body.innerHTML=document.body.innerHTML.replace("Maestro, Visa and other credit/debit cards by <b>Moneybookers</b>","Pago con Diners Club, Mastercard o Visa");
}
onload=x;
我对JS很陌生,说实话我只是无法解决问题,因此IE会读取脚本。
答案 0 :(得分:1)
我从未听说IE浏览器没有读取js文件,我通常会通过添加一个简单的行来验证:
alert('test');
检查文件是否已加载..
如果你收到警报,那么文件已经加载但是IE的代码不能正常工作,那么IE更有可能在IE上没有加载JS ..
答案 1 :(得分:0)
尝试:
<script type="text/javascript" src="http://www.amorame.com/geoff.js"></script>;
看看脚本是否适用于alert('test');
答案 2 :(得分:0)
可能是脚本不能在IE下运行,而不是被IE“读取”。你检查过IE javascript控制台吗?
答案 3 :(得分:0)
这是IE中的一个错误。如果你警告innerhtml你可以看到它被替换。但浏览器并未反映出来。
检查此问题:https://stackoverflow.com/questions/1293427/
您需要使用DOM的更多功能来改变它。这是一个生成dom的小片段(我的学校分配,所以不介意虚拟文本):
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>Creating the Dom!</title>
<link rel="stylesheet" type="text/css" href="createDom.css">
<script type="text/javascript">
function buildbody()
{
var body = document.getElementsByTagName("body")[0];
var theHeader = document.createElement('h1');
var theHeaderTxt = document.createTextNode('Study program Bachelor of ICT');
theHeader.appendChild(theHeaderTxt);
body.appendChild(theHeader);
var theHeader2 = document.createElement('h2');
var theHeader2Txt = document.createTextNode('Introduction');
theHeader2.appendChild(theHeader2Txt);
body.appendChild(theHeader2);
var txtN1 = document.createElement('p');
var pTxt1 = document.createTextNode(
'Western society is based on well functioning but rapidly changing technological applications.\n' +
'However, mere specialisation is no longer enough modern technologistsneed to be capable of forming \n' +
'a global overview of the developments in their branch. Accordingly, graduates from the Faculty of \n' +
'Technology of University Drenthe are broadly educated technologists with an eye for innovation, \n' +
'management and social circumstances. The Faculty of Technology offers a four-year study program \n' +
'Bachelor of ICT.');
txtN1.appendChild(pTxt1);
body.appendChild(txtN1);
var theHeader3 = document.createElement('h2');
var theHeader3Txt = document.createTextNode('Course characters');
theHeader3.appendChild(theHeader3Txt);
body.appendChild(theHeader3);
var pTxt2 = document.createTextNode(
'Work is done on a problem-oriented, project basis, often involving external research, and the \n' +
'practical training periods are completed at interesting positions in the relevant industries.');
var txtN2 = document.createElement('p');
txtN2.appendChild(pTxt2);
body.appendChild(txtN2);
var theHeader4 = document.createElement('h2');
var theHeader4Txt = document.createTextNode('Internship');
theHeader4.appendChild(theHeader4Txt);
body.appendChild(theHeader4);
var pTxt3 = document.createTextNode(
'In the third and fourth year students have the opportunity to put the theory into practice. \n' +
'A company based traineeship of five months in the third year is part of the program and in the \n' +
'fourth year students work on a final graduation project for one semester. Both periods can be \n' +
'spent in the Netherlands or abroad.');
var txtN3 = document.createElement('p');
txtN3.appendChild(pTxt3);
body.appendChild(txtN3);
var linkN1 = document.createElement('a');
var linkTxt1 = document.createTextNode('Click for more information');
linkN1.setAttribute('href','http://www.hbo-i.nl/default.aspx?pageID=24');
linkN1.appendChild(linkTxt1);
body.appendChild(linkN1);
}
</script>
</head>
<body onload="buildbody()">
</body>
</html>
正如您所看到的,文档的主体完全是空的,脚本会生成它。你也必须以这种方式改变dom。
答案 4 :(得分:0)
我使用Internet Explorer出现相同的症状。 一切都归结为IE不支持的箭头功能。
答案 5 :(得分:0)
IE似乎完全忽略了其中某些位置具有非ES5语法的文件。我这样做是为了检查语法兼容性:
npm install -g es-check
es-check es5 offendingFile.js