javascript控制台

When it fails, JavaScript most often dies with barely a whimper. While this is generally a good thing – a failed script won’t usually blow up your page – it can also make finding JavaScript errors a frustrating and time-consuming exercise.

当它失败时,JavaScript几乎绝不会wh之以鼻。 尽管这通常是一件好事-失败的脚本通常不会使您的页面崩溃,但它也会使查找JavaScript错误成为一件令人沮丧且耗时的工作。

In the early days of web development, bug tracking was often accomplished by inserting variable values in alert() windows, which would act as primitive indicators of script behaviour. Today, with many more scripts on web pages, we need much more powerful ways to write and test JavaScript. console, originally developed as part of the Firebug browser extension, now has its own API, and is invaluable for web developers at every skill level.

在Web开发的早期,错误跟踪通常是通过在alert()窗口中插入变量值来完成的,这些变量值可以作为脚本行为的原始指示。 如今,随着网页上更多脚本的出现,我们需要更强大的方法来编写和测试JavaScript。 console最初是作为Firebug浏览器扩展的一部分开发的,现在拥有自己的API,对于每个技能水平的Web开发人员来说都是无价的。

调出控制台 (Bringing Up The console)

While every vendor supports it, the console looks slightly different from one browser to the next, and is reached in a slightly different way in each:

尽管每个供应商都支持它,但控制台在一个浏览器和另一个浏览器之间看起来略有不同,并且在每个浏览器中的访问方式都略有不同:

  • In Chrome: ⌘-Option-J

    在Chrome中: ⌘-Option-J

  • In Firefox: ⌘-Shift-J

    在Firefox中: ⌘-Shift-J

  • In Safari: Ensure that the Developer Menu option is on in Advanced Preferences; use ⌘-Option-C to bring up the console.

    在Safari中:确保“ 高级偏好设置”中的“ 开发人员菜单”选项处于打开状态; 使用⌘-Option-C打开控制台。

零件便签本,零件报告卡 (Part Scratchpad, Part Report Card)

The console fulfills many tasks. It is, among other things:

控制台执行许多任务。 除其他外,它是:

  • An area for JavaScript to report errors JavaScript报告错误的区域
  • A “scratchpad” area to test code before implementation 在实现之前测试代码的“便签本”区域
  • A place for page scripts to output status and tracking information 页面脚本输出状态和跟踪信息的地方

I’ll discuss many more possible uses for console in future articles; for now, let’s take a quick look at the simplest of these features.

在以后的文章中,我将讨论console更多可能用途。 现在,让我们快速看一下这些功能中最简单的功能。

Start up a console, load a basic valid HTML page, and type the following into the console window:

启动控制台,加载基本的有效HTML页面,然后在控制台窗口中键入以下内容:

document.body

Note that the console returns to you the body element, including all of its markup and text. An empty document would return:

请注意,控制台将向您返回body元素,包括其所有标记和文本。 空文档将返回:

<body></body>

Now let’s take it a little further:

现在让我们更进一步:

document.body.style.backgroundColor = "red";

Note that this immediately changes the background of the page: you’re using JavaScript to directly write CSS in real time. Neat, huh?

请注意,这会立即更改页面背景:您正在使用JavaScript实时直接编写CSS 。 整洁吧?

For extra insight, flip to the Elements view and take a closer look at the <body> element in the DOM after taking this step.

要获得更多信息,请转到“元素”视图,并在执行此步骤之后仔细查看DOM中的<body>元素。

Used in this way, the console becomes an excellent tool for playing with and learning JavaScript. Of course, all of this code, and any effect associated with it, disappears as soon as you refresh the page. We’ll look at using the console for working with real scripts on pages next.

以这种方式使用,控制台成为玩耍和学习JavaScript的绝佳工具。 当然,刷新页面后,所有这些代码以及与之相关的任何效果都会消失。 接下来,我们将在控制台上使用控制台来处理真实脚本。

错误捕捉 (Error Catching)

Used as a catchment for errors, the console becomes even more useful. For example, write a script directly on a web page:

用作错误的收集器,控制台变得更加有用。 例如,直接在网页上编写脚本:

artists = ["Daft Punk","DJ Shadow","Amon Tobin"];
artists.push("Front Line Assembly");
console.log("The artists array contains " + artists.length + " elements");

Load the page, and switch to the console window. With console.log() you can “echo out” any variable, or the result of any action.

加载页面,然后切换到控制台窗口。 使用console.log()您可以“回显”任何变量或任何操作的结果。

You can use the console for a lot more than these simple tasks, but I hope this will provide a good start for beginners.

除了这些简单的任务,您还可以使用控制台进行更多操作,但是我希望这将为初学者提供一个良好的开端。

翻译自: https://thenewcode.com/767/Introducing-the-JavaScript-console

javascript控制台

javascript控制台_JavaScript控制台简介相关推荐

  1. HMI-45-【控制台】控制台代码迁移

    HMI-45-[控制台]控制台代码迁移 ​ 今天实在是看不下去控制台了,多媒体先放一下,先搞一下控制台,说好听点就是优化一下控制台控制逻辑. 当前进度 ​ 这个就是今天的成果,就是把转向灯控制和电话控 ...

  2. javascript控制台_超越控制台日志3种在javascript中格式化控制台输出的方法

    javascript控制台 As JavaScript developers, we intuitively use console.log() to debug, print out variabl ...

  3. javascript原理_JavaScript程序包管理器工作原理简介

    javascript原理 by Shubheksha 通过Shubheksha JavaScript程序包管理器工作原理简介 (An introduction to how JavaScript pa ...

  4. javascript语法_JavaScript传播语法简介

    javascript语法 by Ashay Mandwarya ?️?? 由Ashay Mandwarya提供吗? JavaScript传播语法简介 (An introduction to Sprea ...

  5. (6)JavaScript之console控制台

    一.console控制台介绍 在大部分浏览器中,都有一个控制台,内部可以查看 HTML.css 代码,甚至调试代码错误. 浏览器中右键点击审查元素(检查),都可以打开控制台. 快捷键: F12 控制台 ...

  6. javascript 弹窗与控制台日志

    三种弹窗: var flag=confirm("!!!"); //确认弹窗,flag确认获得true,取消获得falsevar info = prompt("!!!&qu ...

  7. javascript中浏览器控制台console.log 输出图片,彩色字体,文字

    浏览器控制台输出图片,彩色字体,文字 if (window.console) {     var cons = console;     if (cons) {         cons.log(&q ...

  8. javascript开关_JavaScript开关案例简介

    javascript开关 In this short article, I will introduce you to JavaScript switch cases and how to use t ...

  9. JavaScript基础01【简介、js编写位置、基本语法(6种基本数据类型)】

    学习地址: 谷粒学院---尚硅谷 尚硅谷最新版JavaScript基础全套教程完整版(140集实战教学,JS从入门到精通) JavaScript基础.高级学习笔记汇总表[尚硅谷最新版JavaScrip ...

最新文章

  1. 串口接收数据与分析处理
  2. win10搭建python环境_win10系统搭建python环境的还原方法
  3. hitTest:withEvent:方法流程
  4. jQuery学习笔记(简介,选择器)
  5. 年前最后一波成绩单,请查收!
  6. Android之在一个类里面注册Handler发送消息在另外一个类里面接收消息
  7. c语言中aver是什么意思_Linux系统top命令中的io使用率,到底是什么意思?
  8. 记一次ora-1652错误的解决过程
  9. 最新升学e网通JS逆向分析
  10. ffmpeg源码分析:transcode()函数
  11. mysql 登录及常用命令
  12. 阶段3 1.Mybatis_12.Mybatis注解开发_2 mybatis注解开发测试和使用注意事项
  13. python中字典教程_python中字典详解
  14. python怎么生成图_python 生成图表
  15. 如何更改html的默认应用,win10如何修改默认应用
  16. Java 面试真题 【继承静态代码块执行时机】
  17. 开关电源个人总结(电感部分与滤波电容)
  18. C/C++ tip: How to detect the operating system type using compiler predefined macros
  19. android 滤镜 原理,android openglse实现滤镜九宫格
  20. 分析会计选择在税收筹划中的运用

热门文章

  1. C语言实现存款利息计算
  2. C/C++段错误问题排查和解决方法
  3. 处理海量数据之awk命令
  4. python示波器 波形数据_python - 将示波器的VISA波形导入Python - 堆栈内存溢出
  5. 乔布斯的创新之道:想象力是第一生产力
  6. 通过瀑布流加深对js的理解
  7. 智鼎在线测评行测题记录
  8. 直流双闭环调速系统的计算机仿真,直流电动机双闭环调速系统的动态特性研究与仿真.doc...
  9. Markdown笔记及常用快捷键(自用)
  10. 《信息安全技术 关键信息基础设施安全保护要求》国家标准在京发布