简体   繁体   English

Internet Explorer 8,9,10 javascript无法正确加载

[英]Internet Explorer 8, 9, 10 javascript not loading correctly

I currently have a working 'dealer locator' on my test page which can be found on the right-hand side of the page 我目前在我的测试页面上有一个工作的“经销商定位器”,可以在页面的右侧找到

http://www.khl.com/dev/american-cranes-and-transport/ http://www.khl.com/dev/american-cranes-and-transport/

It's working fine apart from in dreaded IE, although IE11 seems to work. 尽管IE11似乎有效,但除了可怕的IE之外,它的工作正常。

When you view the page in IE you get a palceholder image which looks horrible, this occurs because the JS looks something like this: 当您在IE中查看页面时,您会看到一个看起来很糟糕的掌上电脑图像,这是因为JS看起来像这样:

<div class="storeNews">


<img src="http://www.khl.com/other_files/khl/dealer-locatot.png"   border="0">


<script language="JavaScript" type="text/javascript"> 

ImgPath='http://www.khl.com/other_files/khl/locate/'; 
ImgPreloadAry=new Array('placeholder.jpg','link3.png','sany3.png','manitex3.png','manitowoc3.png'); 
SRCAry=new Array(); 

for (i=0;i<ImgPreloadAry.length;i++){ 
 SRCAry[i]=new Image(); 
 SRCAry[i].src=ImgPath+ImgPreloadAry[i]; 
} 

function Cng(sel){ 
 document.getElementById('img').src=ImgPath+sel.options[sel.selectedIndex].value; 
 document.getElementById('tbl').style.backgroundImage='url('+(ImgPath+sel.options[sel.selectedIndex].value)+')'; 
} 



var ImgPath='http://www.khl.com/other_files/khl/locate/';
var linksArray = [
  { Img: 'placeholder.jpg', Link : '#', RelatedText :'TEST LINK'},
  { Img: 'link3.png', Link : 'http://www.linkbelt.com/', RelatedText :'Link-belt description and link'},
  {Img:'sany3.png', Link : 'http://www.sanygroup.com/', RelatedText :'Sanny description and link'},
  {Img:'manitex3.png', Link : 'http://www.khl.com/servlet/file/Manitex%20dealer%20ad.pdf?ITEM_ENT_ID=90292&amp;COLLSPEC_ENT_ID=38&amp;ITEM_VERSION=1&amp;download=1',RelatedText : 'Manitex Locator can be downloaded below.'},
  {Img:'manitowoc3.png', Link : 'http://www.manitowoc.com/',RelatedText : 'Manitowoc description and link'},
];

function Cng(sel){ 
   var selectedIndex = sel.selectedIndex;
   document.getElementById('companyLink').href = linksArray[selectedIndex].Link;
   document.getElementById('relatedText').innerHTML= linksArray[selectedIndex].RelatedText;
   document.getElementById('relatedImage').src = ImgPath + linksArray[selectedIndex].Img;
}




//--> 
</script> 
</head> 

Effectively ImgPath=' http://www.khl.com/other_files/khl/locate/ and for some reason IE thinks that this is also an image (not a path). 有效地ImgPath =' http: //www.khl.com/other_files/khl/locate/由于某种原因,IE认为这也是一个图像(不是路径)。

Are there any bright sparks out there who can help me out? 有什么明亮的火花可以帮助我吗?

Kind Regards, Sam 亲切的问候,山姆

Classic trailling comma bug. 经典trailling逗号bug。

.....towoc description and link'},
                                ^^^
                   this comma is invalid and will break your JS in IE.

If you run your JS code through a validator like JSHint, you'll be warned about issues like this. 如果你通过像JSHint这样的验证器运行你的JS代码,你会被警告这样的问题。 And they're also very easy to spot if you use a decent IDE to edit the code, as you'll get syntax highlighting and warnings from that too. 如果你使用一个不错的IDE来编辑代码,它们也很容易被发现,因为你也会从中获得语法高亮和警告。

In addition, you've declared function Cng() twice, which is obviously wrong. 另外,你已经声明了function Cng()两次,这显然是错误的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM