javascript 中 window 的对象

1:html部分

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>Document</title>
    <script type="text/javascript" src="jquery-1.8.2.min.js"></script>
    <script type="text/javascript" src="Window.js"></script>
    <link rel="stylesheet" href="Window.css"/>
</head>
<body>
</body>
</html>


2:css部分

*{
    margin: 0px;
    padding: 0px;
    font-family: "微软雅黑";
    font-size: 14px;
}
body{
    background-color: #3b3c32;
    padding-top: 100px;
}
#window{
    width: 1200px;
    height: auto;
    margin: 0 auto;
}
ul{
    list-style: none;
    /*float: left;*/
    position: relative;
}
ul>ul{
    margin-left: 60px;
    height: auto;
}
span.type{
    font-weight: bolder;
    width: 400px;
    height: 30px;
    float: left;
    cursor: default;
}
span.object0{
    color: green;
    cursor: pointer;
}
span.object1{
    color: green;
    cursor: pointer;
}
span.object2{
    color: green;
    cursor: pointer;
}
span.object3{
    color: green;
    cursor: pointer;
}
span.object4{
    color: green;
    cursor: pointer;
}
span.object5{
    color: green;
    cursor: pointer;
}
span.function{
    color: brown;
}
span.number{
    color: #0b6694;
}
span.string{
    color: yellowgreen;
}
span.boolean{
    color: turquoise;
}
h4{
    width: 100%;
    text-align: center;
    margin-bottom: 30px;
    font-size: 18px;
    font-weight: bolder;
}
li{
    height: 30px;
    line-height: 30px;
    float: left;
    width: 100%;
    color: turquoise;
    /*background-color: #808080;*/
    /*border-bottom: 1px solid white;*/
    overflow: hidden;
    /*background-color: lightseagreen;*/
}


3:js部分

$(function(){
    function printObj(obj,title,after,dept){

        var html = '';
        //html += '<h4>'+title+'<h4/>';
        html += '<ul id="'+title+'">';
        //document.write('<hr/>');
        //document.write('<h3>'+title+'<h3/>');
        for(pro in obj) {
            if (pro != 'printObj') {
                var type = typeof obj[pro];
                html += '<li class="li">';
                html += '<span class="type';
                if(type == 'object'){
                    html += ' object'+dept+'" dept="'+dept+'" ';
                    for(i=1;i<=dept;++i){
                        html += 'object'+i+'="'+$(after).attr('object'+i)+'" ';
                    }
                    html+= 'object'+parseInt(i) +'="'+pro;
                }
                if(type == 'function'){
                    html+= ' function';
                }
                if(type == 'number'){
                    html+= ' number';
                }
                if(type == 'boolean'){
                    html+= ' boolean';
                }
                if(type == 'string'){
                    html+= ' string';
                }
                html += '">'+ title + '.['  + type + ']</span>' +title+'.' + pro + ' = ' + obj[pro] + '<br/>';
                html += '</li>';
            }
        }
        html += '</ul><br/>'
        if(after == ''){
            $("body").after(html);
        }else{
            $(after).parent().after(html);
        }
        $(".object"+dept).bind('click',function(){
            if(parseInt($(this).attr("opened")) == 1){
                if($(this).parent().next().is("ul")){
                    var id = $(this).parent().next().attr("id");
                    //alert(id);
                    $("#"+id).css('display','none');
                    $(this).attr("opened",'0');
                    return false;
                }
            }else if(parseInt($(this).attr("opened")) == 0){
                if($(this).parent().next().is("ul")){
                    var id = $(this).parent().next().attr("id");
                    $("#"+id).css('display','block');
                    $(this).attr("opened",'1');
                    return false;
                }
            }else {
                var dept = $(this).attr("dept");
                $(this).attr("opened", '1');
                if (dept == 0) {
                    var obj1 = $(this).attr("object1");
                    if (window[obj1] == null) {
                        alert('window.' + obj1 + ' is an object but null !!!');
                        return false;
                    }
                    printObj(window[obj1], 'window-' + obj1, this, 1);
                } else if (dept == 1) {
                    var obj1 = $(this).attr("object1");
                    var obj2 = $(this).attr("object2");
                    if (window[obj1][obj2] == null) {
                        alert('window.' + obj1 + '.' + obj2 + ' is an object but null !!!');
                        return false;
                    }
                    printObj(window[obj1][obj2], 'window-' + obj1 + '-' + obj2, this, 2);
                } else if (dept == 2) {
                    var obj1 = $(this).attr("object1");
                    var obj2 = $(this).attr("object2");
                    var obj3 = $(this).attr("object3");
                    if (window[obj1][obj2][obj3] == null) {
                        alert('window.' + obj1 + '.' + obj2 + '.' + obj3 + ' is an object but null !!!');
                        return false;
                    }
                    printObj(window[obj1][obj2][obj3], 'window-' + obj1 + '-' + obj2 + '-' + obj3, this, 3);
                } else if (dept == 3) {
                    var obj1 = $(this).attr("object1");
                    var obj2 = $(this).attr("object2");
                    var obj3 = $(this).attr("object3");
                    var obj4 = $(this).attr("object4");
                    if (window[obj1][obj2][obj3][obj4] == null) {
                        alert('window.' + obj1 + '.' + obj2 + '.' + obj3 + '.' + obj4 + ' is an object but null !!!');
                        return false;
                    }
                    printObj(window[obj1][obj2][obj3][obj4], 'window-' + obj1 + '-' + obj2 + '-' + obj3 + '-' + obj4, this, 4);
                } else if (dept == 4) {
                    var obj1 = $(this).attr("object1");
                    var obj2 = $(this).attr("object2");
                    var obj3 = $(this).attr("object3");
                    var obj4 = $(this).attr("object4");
                    var obj5 = $(this).attr("object5");
                    if (window[obj1][obj2][obj3][obj4][obj5] == null) {
                        alert('window.' + obj1 + '.' + obj2 + '.' + obj3 + '.' + obj4 + '.' + obj5 + ' is an object but null !!!');
                        return false;
                    }
                    printObj(window[obj1][obj2][obj3][obj4][obj5], 'window-' + obj1 + '-' + obj2 + '-' + obj3 + '-' + obj4 + '-' + obj5, this, 5);
                }
            }
            return false;
        });
    }
    //alert('aaa');
    printObj(window,'window','',0);
});


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值