HTML5技术

详解Google Chrome浏览器(操作篇) - Alan_beijing(3)

字号+ 作者:H5之家 来源:H5之家 2017-02-13 15:01 我要评论( )

You can inspect HTML nodes and JavaScript objects in more detail by using the console commands listed in Table 5-1. Type the command-line APIs interactively within the console. If your scripts share

You can inspect HTML nodes and JavaScript objects in more detail by using the console commands listed in Table 5-1. Type the command-line APIs interactively within the console.
If your scripts share the same function name as a Command-Line API function, the function in your scripts takes precedence.

The functions listed in Table 5-1 are regular JavaScript functions that are part of the Web Inspector environment. That means you can use them as you would any JavaScript function. For example, you can assign a chain of Console API commands to a variable to create a useful shorthand. Listing 5-1 shows how you can quickly see all event types attached to the selected node.

After defining this function, inspect the magnifying glass in the top-right corner of this webpage, and type evs() in the console. An array containing the string “click” is returned, because there is a click event listener attached to that element.
Of course, these functions shouldn’t be included in your website’s JavaScript files because they are not available in the browser environment. Only use these functions in the Web Inspector console. Console functions you can include in your scripts are described in Console API.

Console API

详解

1、console.assert(expression, object)

定义:Writes an error to the console when the evaluated expression is false.

译文:当计算表达式为假时,向控制台输出错误信息。

示例1:

function greaterThan(a,b) { console.assert(a > b, {"message":"a is not greater than b","a":a,"b":b}); } greaterThan(5,6);

result:

示例2:

var isFalse=false; console.assert(isFalse,"Output Info when evaluated expression is false");

result:

2、console.clear()

定义:Clears the console.If the Preserve log checkbox is enabled, console.clear() is disabled. However, pressing the clear console button () or typing the shortcut Ctrl+L while the Console is in focus still works.See Clearing the console for more information.

译文:清楚控制台信息。如果保护日志复选框被启用,则console.clear()被禁用。然而,当控制台的焦点仍在工作时,按明确的控制台按钮(明确控制台按钮)或输入快捷键Ctrl + L。

3、console.count(label)

定义:Writes the the number of times that count() has been invoked at the same line and with the same label.

译文:输出被调用相同的行和相同的标签的总次数。

示例1:

function login(name) { console.count(name + ' logged in'); }

result:

4、console.debug(object [, object, ...])

定义:Identical to console.log().

译文:与console.log()一样;

小结:功能与console.log()一样。

5、console.dir(object)

定义:Prints a JavaScript representation of the specified object. If the object being logged is an HTML element, then the properties of its DOM representation are printed.

译文:打印具体对象的JavaScript表示。如果被记录的对象是一个HTML元素,然后打印DOM表示的属性。

示例1:

console.dir(document)

result:

6、console.dirxml(object)

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • HTML5 拖放(Drag 和 Drop)详解与实例 - 孟然

    HTML5 拖放(Drag 和 Drop)详解与实例 - 孟然

    2017-02-06 16:01

  • 详解google Chrome浏览器(理论篇) - Alan_beijing

    详解google Chrome浏览器(理论篇) - Alan_beijing

    2017-01-31 12:00

  • 不常见但很有用的chrome调试工具使用方法 - 小火柴的蓝色理想

    不常见但很有用的chrome调试工具使用方法 - 小火柴的蓝色理想

    2017-01-24 14:00

  • Microsoft Edge与Google Chrome那些不同的举止 - fyter

    Microsoft Edge与Google Chrome那些不同的举止 - fyter

    2017-01-16 12:00

网友点评
n