需要帮助来替换stopPropagation()javascript

时间:2014-02-11 09:21:19

标签: javascript html css internet-explorer

我需要一些关于我的Javascript的帮助,问题是我的JavaScript代码在Internet Explorer 8以及Internet Explorer 7上无法正常工作,它给出的错误是说Internet Explorer 8上不支持stopPropagation() 7.所以我需要一些帮助来解决这个问题,并在Internet Explorer 8/7上工作。

FIDDLE


var dataSource = ({
    "Pen": ({
        "Cello": ({
            "C2": ({}),
            "C1": ({})
        }),
            "Parker": ({
            "P2": ({}),
            "P1": ({})
        })
    })
});
 var traverseObject = function (obj) {
        var ul = document.createElement("ul"),
            li;

        for (var prop in obj) {
            li = document.createElement("li");
            li.appendChild(document.createTextNode(prop));
            li.onclick = function(e) {
                var classNames = this.className;
                if (classNames.indexOf("hidden") == -1) {
                    this.className += "hidden";
                } else {
                    this.className = this.className.replace("hidden", "");
                }
                e.stopPropagation();
            }

            if (typeof obj[prop] == "object" && Object.keys(obj[prop]).length) {
                console.log(Object.keys(obj[prop]).length + "  " + Object.keys(obj[prop]));
                li.appendChild(traverseObject(obj[prop]));
            } else {
                li.className += "leaf";
            }
            ul.appendChild(li);
            console.log(ul);
        }
        return ul;
    };


window.onload = function () {
    document.getElementById("dvList1").appendChild(traverseObject(dataSource));

}

谢谢

0 个答案:

没有答案