我需要JavaScript幫助,因爲它在Internet Explorer 7上測試時表現異常,但它在Internet Explorer 8,Google Chrome和Firefox上正常工作。問題是,當我點擊P1,P2,Cello,C2,C1的極端左側的綠色陰影區域時,我的樹倒塌回到不該發生的項目。它應該是這樣的,如果我點擊帕克或單元格或項目,其子部分將被關閉或打開。JavaScript與JavaScript無法在Internet Explorer 7上正常工作
var Objectkeys = function(obj){
a = []
for(var prop in obj){
if (obj.hasOwnProperty(prop)) {
a.push(prop);
}
};
return a;
},
traverseObject = function (obj) {
var ul = document.createElement("ul"),
li,span;
for (var prop in obj) {
li = document.createElement("li");
li.appendChild(document.createTextNode(prop));
li.style.backgroundColor = "green";
li.onclick = function(e) {
e = e || window.event;
if ((e.target || e.srcElement).tagName !== "LI") return;
var classNames = this.className;
if (classNames.indexOf("hidden") == -1) {
this.className += "hidden";
} else {
this.className = this.className.replace("hidden", "");
}
if (!e)
e = window.event;
if (e.stopPropagation) {
e.stopPropagation();
}
else {
e.cancelBubble = true;
}
}
if (typeof obj[prop] == "object" && Objectkeys(obj[prop]).length) {
li.appendChild(traverseObject(obj[prop]));
} else {
li.className += "leaf";
}
ul.appendChild(li);
console.log(ul);
}
return ul;
},
sortedObject = function (obj) {
document.getElementById("dvList2").innerHTML = "";
var ul = document.createElement("ul"),
li,keys = Objectkeys(obj).sort();
for (prop in keys) {
var li = document.createElement("li");
li.appendChild(document.createTextNode(keys[prop]));
li.onclick = function(e) {
e = e || window.event;
if ((e.target || e.srcElement).tagName !== "LI") return;
var classNames = this.className;
if (classNames.indexOf("hidden") == -1) {
this.className += "hidden";
} else {
this.className = this.className.replace("hidden", "");
}
if (!e)
e = window.event;
if (e.stopPropagation) {
e.stopPropagation();
}
else {
e.cancelBubble = true;
}
}
if (typeof obj[keys[prop]] == "object" && Objectkeys(obj[keys[prop]]).length) {
li.appendChild(sortedObject(obj[keys[prop]]));
} else {
li.className += "leaf";
}
ul.appendChild(li);
console.log(ul);
}
return ul;
};
window.onload = function() {
document.getElementById("dvList1").appendChild(traverseObject(dataSource));
document.getElementById("hlGSL").onclick = function(){document.getElementById("dvList2").appendChild(sortedObject(dataSource));}
}
單擊jsfiddle中的「JSHint」按鈕。我會開始修復所有這些警告。 – elclanrs
先生,它完成了,現在請幫我解決問題 – user3314588
小提琴仍然是一樣的...但我沒有IE7,我會看這裏http://stackoverflow.com/questions/16112345/developer-tools-在ie-ie7查看控制檯日誌消息,並嘗試調試代碼,或使用jQuery – elclanrs