一个用js实现控制台控件的代码

 更新时间:2007年09月04日 11:46:04   作者:  
复制代码 代码如下:

<body margin="0">
</body>
<script>
    function Console(width,height,command)
    {
        var container=document.createElement("div");
        this.container=container;

        container.runtimeStyle.width=(width);
        container.runtimeStyle.height=(height);
        container.runtimeStyle.margin="0px";
        container.runtimeStyle.backgroundColor="black";
        container.runtimeStyle.fontFamily="Terminal";
        container.runtimeStyle.color="white";
        container.runtimeStyle.fontSize="16px";
        this.output=document.createElement("div");
        container.appendChild(this.output);
        container.innerHTML+="js>"
        this.input=document.createElement("input");
        container.appendChild(this.input);
        this.input.runtimeStyle.backgroundColor="black";
        this.input.runtimeStyle.borderWidth="0px";
        this.input.runtimeStyle.color="white";
        this.input.runtimeStyle.fontFamily="Terminal";
        this.input.runtimeStyle.width="90%"
        this.input.runtimeStyle.fontSize="16px"
        this.input.runtimeStyle.position="relative";
        this.input.runtimeStyle.top="2px";
        command=command||function(str)
        {

            var e;
            try{
                var r=eval(str);
            } catch(e) {
                return "Bad command";
            }
            return r;

        }

        this.input.command=function()
        {
            this.parentNode.childNodes[0].innerHTML+=this.value+'<br/>'
            this.parentNode.childNodes[0].innerHTML+=(command(this.value)+"<br/>")

        }
        this.input.onkeyup=new Function("e","e=e||event;if(e.keyCode!=13)return;this.command();this.value='';");
        this.appendto=function(parent)
        {
            parent.appendChild(this.container);
        }
        container=null;
    }

    //var db=new DrawingBoard(100,100)
    //db.drawLine([5,5],[36,44],"red")
    //document.body.appendChild(db.container);
    var c=new Console("100%","100%");
    c.appendto(document.body);

</script>

相关文章

  • document.documentElement和document.body区别介绍

    document.documentElement和document.body区别介绍

    body是DOM对象里的body子节点,即body标签,documentElement 是整个节点树的根节点root,详细介绍请看本文,感兴趣的朋友可以参考下
    2013-09-09
  • JavaScript 版本自动生成文章摘要

    JavaScript 版本自动生成文章摘要

    搜了搜这个,发现找不到答案。所以自己写了一个,很多程序绕过这个问题,往往人工来决定在何处截断 ,太麻烦了。
    2008-07-07
  • JavaScript Event学习补遗 addEventSimple

    JavaScript Event学习补遗 addEventSimple

    这里有个addEventSimple和removeEventSimple函数,有时候需要不那么显眼的事件处理程序的时候我就用这两个函数注册。
    2010-02-02
  • 浅析JavaScript中两种类型的全局对象/函数

    浅析JavaScript中两种类型的全局对象/函数

    这篇文章主要介绍了JavaScript中两种类型的全局对象/函数。需要的朋友可以过来参考下,希望对大家有所帮助
    2013-12-12
  • 全面解析JavaScript Module模式

    全面解析JavaScript Module模式

    这篇文章主要介绍了JavaScript Module模式的相关资料,文中讲解非常细致,代码帮助大家更好的理解和学习,感兴趣的朋友可以了解下
    2020-07-07
  • 使用JS获取当前地理位置方法汇总

    使用JS获取当前地理位置方法汇总

    这篇文章主要介绍了使用JS获取当前地理位置方法汇总,需要的朋友可以参考下
    2014-12-12
  • 12行javascript代码绘制一个八卦图

    12行javascript代码绘制一个八卦图

    本文给大家分享的是使用有限的代码绘制八卦图,算是考核下自己对于javascript的理解,这里推荐给大家,有需要的小伙伴参考下。
    2015-04-04
  • 一篇文章掌握RequireJS常用知识

    一篇文章掌握RequireJS常用知识

    一篇文章掌握RequireJS常用知识,通过本文,你可以对模块化开发和AMD规范有一个较直观的认识,并详细地学习RequireJS这个模块化开发工具的常见用法,感兴趣的小伙伴们可以参考一下
    2016-01-01
  • JavaScript实现计数器基础方法

    JavaScript实现计数器基础方法

    这篇文章主要为大家详细介绍了JavaScript实现计数器的基础方法
    ,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-10-10
  • three.js实现3D视野缩放效果

    three.js实现3D视野缩放效果

    这篇文章主要为大家详细介绍了three.js实现3D视野缩放效果,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-11-11

最新评论