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

代码如下:

<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>

(0)

相关推荐

  • 如何使Chrome控制台支持多行js模式——意外发现

    一直以来,Chrome控制台都缺少象IE调试台那样的多行执行模式.  今天意外发现Chrome其实也支持多行模式.默认在Chrome控制台上输入回车后会执行该命令,只需要通过输入Shift+Enter来新建行即可.

  • javascript中常见的3种信息提示框(alert,prompt,confirm)

    1.警告提示框 alert("文本"). ex. function disp_alert() { alert("我是警告框!!"+'\n'+"hhah")//有折行 } [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行] 2.确认提示框(confirm,返回true或者false) function show_confirm() { var r=confirm("Press a button!"); if (r==tr

  • Js 订制自己的AlertBox(信息提示框)

    本文制作一个用户自定义的AlertBox,效果如图:js文件中插入如下代码: 复制代码 代码如下: // JScript 文件 // constants to define the title of the alert and button text. var ALERT_TITLE = "Oops!"; var ALERT_BUTTON_TEXT = "Close"; // over-ride the alert method only if this a new

  • 利用浏览器的Javascript控制台调试PHP程序

    PHP是一种服务器端脚本语言,用来开发动态web应用程序.与JAVA相比,没有一个好的服务器端调试工具是其限制之一.通常我们都是在PHP代码中添加echo.var_dump等语句,将变量.数组的值显示在浏览器中来达到调试的目的. 现在,越来越多的浏览器都有了开发这工具或者Javascript控制台,通过这些工具,我们可以很方便的显示PHP代码中的变量或数组值.下面我们来做一个例子.例子中的PHP代码有四个跟踪级别:info, warn, log, error,开发人员可以使用浏览器控制台来显示错

  • javascript控制台详解

    一.显示信息的命令 console.log(); //控制台输入 网页中不会输出 console.info(); //一般信息 console.debug(); //除错信息 console.warn(); //警告提示 console.error(); //错误提示 "console.log();" 可以用来取代 "alert();" 或 "document.write();" 比如,在网页中写入 "console.log("

  • JavaScript中输出信息的方法(信息确认框-提示输入框-文档流输出)

    js中输出信息的方法内容如下所示: 1.文档流输出 document.write('hello'); 2.输出信息提示框 模态对话框 window.alert('要输出显示的内容'); 或 alert('要输出显示的内容'); alert(n); 3.信息确认框 var f = window.confirm('是否要进入新浪网'); confirm(""); if(f){ location.href = 'http://www.sina.com.cn'; } 4.提示输入框 windo

  • JS简单实现仿百度控制台输出信息效果

    本文实例讲述了JS简单实现仿百度控制台输出信息效果.分享给大家供大家参考,具体如下: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> </head> <body> <h3>打开控

  • AngularJS 如何在控制台进行错误调试

    当我们在编写 AngularJS 的应用时,通过 Chrome, Firefox, 和 IE 的 JavaScript 控制台来获取隐藏在应用之中的数据(Data)和服务(Service) 是一件非常具有挑战性的工作.下面列出了一些简单的小窍门,可以帮助我们使用 Javascript 控制台来监视和控制一个正在运行的 Angular 应用,使其更加容易测试.修改甚至是实时的编写 Angular 应用. 1: 获取 Scopes (作用域) 我们可以使用一行 JS 代码来获取任何的 Scope (

  • js调试系列 控制台命令行API使用方法

    先打开百度,然后按 F12 打开后,如果不是 Console 项的就点击 Console 这项,因为我们要在控制台操作.. 看到如下内容: 好了我们先清空内容,可以右击选 Clear console 菜单,或者输入 clear() 都行. 接着,我们输入 document.getElementById('kw1'); 然后回车,就可以看到 id 为 kw1 的元素信息了. 是不是很简单.下一步是用 console.dir 查看该元素信息. 输入 console.dir(document.getE

  • 禁用JavaScript控制台调试的方法

    有几个巨头公司,即Facebook和Netflix,决定禁止用户在控制台(console)执行JavaScript命令. 最初这是 由Facebook开始的 ,用于防止恶意用户通过JavaScript控制台执行特定的命令散播消息(发送给所有Facebook用户大量垃圾信息). 当然这受到很多指责,但在我参与之前, 他们使用的代码 如下所示: 复制代码 代码如下: // 看起来 Netflix 似乎是唯 Facebook 马首是瞻 [https://news.ycombinator.com/ite

随机推荐