我的测试页面上目前有一个可用的“经销商定位器”,可以在页面右侧找到
http://www.khl.com/dev/american-cranes-and-transport/
尽管 IE11 似乎可以工作,但除了可怕的 IE 之外,它工作得很好。
当你在 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&COLLSPEC_ENT_ID=38&ITEM_VERSION=1&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>
有效地 ImgPath=' http://www.khl.com/other_files/khl/locate/由于某种原因 IE 认为这也是一个图像(而不是路径)。
有什么聪明的人可以帮助我吗?
亲切的问候, 山姆
最佳答案
经典的尾随逗号错误。
.....towoc description and link'},
^^^
this comma is invalid and will break your JS in IE.
如果您通过 JSHint 之类的验证器运行 JS 代码,您将会收到有关此类问题的警告。如果您使用像样的 IDE 编辑代码,它们也很容易发现,因为您也会从中得到语法突出显示和警告。
此外,您还声明了两次 function Cng()
,这显然是错误的。
关于javascript - Internet Explorer 8、9、10 javascript 无法正确加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20222632/