我有一個html調用這個js文件。 html和js在ie9和更高版本中工作正常,但由於某種原因,ie8不能使用此js文件,是否有可能html文件沒有加載文件,或者代碼有問題?JS代碼不能在IE8中工作?
function countTotalByClassName(klass){
total=0;
var arr = document.getElementsByClassName(klass);
for (var index = 0; index < arr.length; index++) {
// console.log(arr[index].checked);
if(arr[index].checked){
total=total+1;
}
};
return total;
} // END countTotalByClassName()
/* getGreatestChoice()
*
* Given an array of hashes, return the one with the highest number.
*
*/
function getGreatestChoice(arr){
res="";
size=0;
for (var i = 0; i < arr.length; i++) {
if (arr[i].count > size){
res=arr[i].name;
}
}
return res;
} // END getGreatestChoice()
function results(){
item1 = {};
item2 = {};
item3 = {};
item4 = {};
arr=[]; // array of items
// BEGIN BUILD HASH ARRAY
item1["name"]="<h1>Lorem1</h1><p>random text</p><img src='img/Hi.png' class='img-responsive'>";
item1["count"]=countTotalByClassName("A");
arr.push(item1);
item2["name"]="<h1>Lorem2</h1><p>random text</p><img src='img/Hi.png' class='img-responsive'>";
item2["count"]=countTotalByClassName("B");
arr.push(item2);
item3["name"] = "<h1>Lorem3</h1><p>random text</p><img src='img/Hi.png' class='img-responsive'>";
item3["count"] = countTotalByClassName("C");
arr.push(item3);
item4["name"] = "<h1>Lorem4</h1><p>random text</p><img src='img/Hi.png' class='img-responsive'>";
item4["count"] = countTotalByClassName("D");
arr.push(item4);
// END BUILD HASH ARRAY
res=getGreatestChoice(arr);
document.getElementById('result').innerHTML = res;
document.getElementById('result').style.width = '100%';
document.getElementById('result').style.backgroundColor = '#F0F0F0';
document.getElementById("result").style.padding="5px 10px 10px 10px";
} // END results()
開發者控制檯是否輸出任何內容? – Nick
定義「不工作」。任何錯誤記錄,或不是預期的結果等? –
看起來像['getElementsByClassName'](https://developer.mozilla.org/en-US/docs/Web/API/document.getElementsByClassName#Browser_compatibility)不在IE8 –