显示错误无法读取未定义的属性“样式”

时间:2016-11-09 15:15:23

标签: javascript

function InitMenu() {
    var bar = menuBar.children
    for (var i = 0; i < bar.length; i++) {
        var menu = eval(bar[i].menu) menu.style.visibility = "hidden"
        bar[i].onmouseover = new Function("ShowMenu(" + bar[i].id + ")") var Items = menu.children
        for (var j = 0; j < Items.length; j++) {
            var menuItem = eval(Items[j].id) if (menuItem.menu != null) {
                menuItem.innerHTML += "<Span Id=" + menuItem.id + "_Arrow class='Arrow'>4</Span>" //var tmp = eval(menuItem.id+"_Arrow")
                    // tmp.style.pixelLeft = menu.getBoundingClientRect().Right //- tmp.offsetWidth - 15
                FindSubMenu(menuItem.menu)
            }
            if (menuItem.cmd != null) {
                menuItem.onclick = new Function("Do(" + menuItem.id + ")")
            }
            menuItem.onmouseover = new Function("highlight(" + Items[j].id + ")")
        }
    }
}

1 个答案:

答案 0 :(得分:-1)

eval只能在数据为json对象时使用。我假设你在一个名为&#34; menuBar&#34;

的div中有一个菜单
var menuBar=document.getElementById("menuBar");
function InitMenu() {
    var bar = menuBar.childNodes;
    for (var i = 0; i < bar.length; i++) {
        var menu = bar[i];
        menu.style.visibility = "hidden";
        bar[i].onmouseover = new Function("ShowMenu(" + bar[i].id + ")") var Items = menu.children
        for (var j = 0; j < Items.length; j++) {
            var menuItem = eval(Items[j].id) if (menuItem.menu != null) {
                menuItem.innerHTML += "<Span Id=" + menuItem.id + "_Arrow class='Arrow'>4</Span>" //var tmp = eval(menuItem.id+"_Arrow")
                    // tmp.style.pixelLeft = menu.getBoundingClientRect().Right //- tmp.offsetWidth - 15
                FindSubMenu(menuItem.menu)
            }
            if (menuItem.cmd != null) {
                menuItem.onclick = new Function("Do(" + menuItem.id + ")")
            }
            menuItem.onmouseover = new Function("highlight(" + Items[j].id + ")")
        }
    }
}