2011-11-27 86 views
1

我正在使用JavaScript来覆盖我的网站第三方购物车中的一些预设选项。 该脚本在Chrome和Firefox中完美工作,但它根本无法在Internet Explorer中正常工作。Internet Explorer不读取Js文件

我的剧本是<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

在所有版本的IE? –

回答

1

我从来没有听说过的IE不读一个js文件,我通常通过添加一个简单的线条验证:

alert('test'); 

检查文件是否被加载..

,如果你得到警报,然后该文件被加载,但代码没有针对IE浏览器正常工作,其将更有可能再IE不加载JS所有..

+0

对不起人们,应该更清楚。 Internet Explorer正在加载js,它只是不执行所有功能,脚本的目的是替换页面中存在的文本,还从预置形式中删除单选按钮选项。脚本中的所有操作都在Chrome和Firefox中成功执行,但是只有删除单选按钮功能在浏览器中工作,文本的替换功能不会在资源管理器中执行,这要感谢您的关注! – LEOPM

0

尝试:

<script type="text/javascript" src="http://www.amorame.com/geoff.js"></script>;

,看看脚本工作与alert('test');

+0

对不起人们,应该已经更清楚了。 Internet Explorer正在加载js,它只是不执行所有功能,脚本的目的是替换页面中存在的文本,还从预置形式中删除单选按钮选项。脚本中的所有操作都在Chrome和Firefox中成功执行,但是只有删除单选按钮功能在浏览器中工作,文本的替换功能不会在资源管理器中执行,这要感谢您的关注! – LEOPM

+0

什么版本的IE?代码可能不兼容。使用跨浏览器的jQuery。 –

0

这可能是IE浏览器下无法正常工作,而不是没有剧本由IE“读”。你检查了IE浏览器的JavaScript控制台?

0

这是IE中的一个bug。如果你警告innerhtml,你可以看到它被替换。但浏览器不反映它。

入住这太问题:https://stackoverflow.com/questions/1293427/

您需要使用DOM的更多的功能来改变它。这里是产生一个DOM一个小片段(我校分配新建分配FY,所以不介意虚拟文本):

<!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。

相关问题