window对象属性查询器

点击“查询”按钮,展示window对象的属性表格。点击任意属性名称进入查看。如点击属性navigator。
这里写图片描述
这里写图片描述

代码清单

<meta name="renderer" content="webkit">
<html>
    <head>
        <meta charset="GBK"/>
        <style>         
            #show{
                margin: 10px auto;
                padding: 10px;
                background-color : #ccf;
                height: 550px;
                overflow-y: scroll;
            }

            .prop{
                cursor:pointer;
                text-decoration:underline;

            }

            .prop_table{
                margin: 10px auto;
                border: 1px black solid;
                width: 1100px;
                display: block;         
            }

            .prop_table tr:nth-child(odd)
            {
                background-color: #ff9;
            }

            .prop_table tr:nth-child(even)
            {
                background-color: #fff;
            }

            .prop_table caption{
                font-weight: bold;
                font-size: 24px;
                text-align: left;
            }

            .prop_table th{
                border-right: 1px black solid;
                padding-left: 5px;
                text-align: left;
            }

            .prop_table td{
                padding-left: 5px;
                text-align: left;
            }

            .topBtn{
                float: right;

                right: 50px;
                bottom: 50px;
                position: absolute;

                border: 2px solid black;
                width: 50px;
                height: 50px;
                background-color : #fff;
                text-align: center;
                line-height: 50px;
            }

            .topBtn a{
                display: block;
                width: 100%;
                height: 100%;
            }
            .topBtn:hover{
                background-color : #aaa;
                cursor: pointer;
            }
        </style>

    </head>
    <body>
        <div>
            <label for="dhtml-props">window的属性查询</label>
            <button id="search" onclick="doSearch()">查询</button>
            <button id="back" onclick="back()">返回上一级</button>

        </div>
        <div id="show" > 

        </div>
        <div class="topBtn"><a href="#top">TOP</a></div>
        <script>            
            var prop_stack = [];

            function push(prop){
                if (prop == "")
                    return;

                prop_stack.push(prop);
            }

            function pop(){
                return prop_stack.pop();
            }

            function printPropNames(){
                var s = "";
                for (var p in prop_stack)
                {
                    s+=prop_stack[p] + ".";
                }

                if (s == "")
                {
                    return "window";
                }
                else
                {
                    return "window." + s.substring(0, s.length -1 );
                }

            }

            function seekProp(){
                var len = prop_stack.length;
                var s = window;
                for (var i = 0; i < len ; i++)
                {
                    s = s[prop_stack[i]];
                }
                return s;
            }

            function back(){
                showKv(pop());
            }
            function showKv(){
                var str = "<table id='top' class='prop_table'><caption>" + printPropNames() + "</caption><tbody>";
                var father = seekProp();
                var unsortedPNames = []
                for (var pName in father)
                {
                    if (father == window && (pName == 'prop_stack' || pName == 'push' || pName == 'pop' || pName == 'printPropNames' || pName == 'seekProp' || pName == 'back' || pName == 'showKv' || pName == 'doSearch' || pName == 'clear'))
                    {
                        continue;
                    }

                    //将属性名称存放到一个临时数组
                    unsortedPNames.push(pName);

                }
                //对属性名称排序
                var sortedPNames = unsortedPNames.sort();

                //按排序的顺序输出属性及属性值
                for (var pName in sortedPNames)
                {
                    str += "<tr><th><a class=\"prop\" onclick=\"showKv(push('"+ sortedPNames[pName] + "'))\">" + sortedPNames[pName] + "</a>" + "</th><td>" + father[sortedPNames[pName]] + "</td></tr>";
                }

                str += "</tbody></table>";          

                document.getElementById("show").innerHTML = str;
                scrollTop();
            }

            function scrollTop()
            {
                document.getElementById('top').scrollIntoView();
            }

            function doSearch(){

                clear();
                showKv(push(""));

            };


            function clear(){
                document.getElementById("show").innerHTML = "";
                prop_stack = [];
            }
            document.onkeydown = function(event_e){
                if (window.event)
                {

                    event_e = window.event;
                    var int_keycode = event_e.charCode || event_e.keyCode;

                    //console.log(int_keycode);

                    if (int_keycode == 13){
                        document.getElementById("search").click();
                    }
                    if (int_keycode == 27){
                        clear();
                    }
                }
            }

        </script>
    </body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值