js輸出到控制台

來源:互聯網
上載者:User

標籤:io   使用   ar   java   strong   sp   div   on   cti   

console.log(object[, object, ...])
在控制台輸出一條訊息。如果有多個參數,輸出時會用空格隔開這些參數。

第一個參數可以是一個包含格式化預留位置輸出的字串,例如:

console.log("The %s jumped over %d tall buildings", animal, count);

上面的例子可以用下面的無格式化預留位置輸出的代碼替換:

console.log("The", animal, "jumped over", count, "tall buildings");

並且,這兩種方式是可以組合使用的。如果使用了格式化預留位置,而提供的參數的個數多於預留位置的個數,那麼,多餘的參數會以空格分隔的方式附加在字串後面,就像:

console.log("I am %s and I have:", myName, thing1, thing2, thing3);

如果參數是一個Javascript對象,那麼在控制台輸出的就不是靜態文字,而是一個可互動的超連結,點擊超連結可以查看該對象的HTML, CSS, Script, DOM視窗,可用格式化字串%o代替Javascript對象。

console.log("Body tag is %o", document.body);

格式化字串列表:

格式化字串 類型
%s 字串
%d, %i 整型(暫不支援數字型)
%f 浮點型 (暫不支援數字型) 
%o 連結化物件

console.debug(object[, object, ...])
在控制台輸出一條訊息,包含一個指向代碼調用位置的超連結。假如是直接在控制台輸入該命令,就不會出現超連結(和console.log()一樣)。

console.info(object[, object, ...])
在控制台輸出一條帶有“資訊”表徵圖的訊息和一個指向代碼調用位置的超連結。

console.warn(object[, object, ...])
在控制台輸出一條帶有“警告”表徵圖的訊息和一個指向代碼調用位置的超連結。

console.error(object[, object, ...])
在控制台輸出一條帶有“錯誤”表徵圖的訊息和一個指向代碼調用位置的超連結。

console.assert(expression[, object, ...])
測試運算式expression是否為真。如果不是真,會在控制台寫一條訊息並拋出異常

console.dir(object)
以列表形式輸出一個對象的所有屬性,有點和你查看DOM視窗相類似。

console.dirxml(node)
輸出一個HTML或者XML元素的XML原始碼。和你在HTML視窗看到的相似。

console.trace()
Prints an interactive stack trace of JavaScript execution at the point where it is called.

The stack trace details the functions on the stack, as well as the values that were passed as arguments to each function. You can click each function to take you to its source in the Script tab, and click each argument value to inspect it in the DOM or HTML tabs.

console.group(object[, object, ...])
輸出一條訊息,並開啟一個嵌套塊,塊中的內容都會縮排。調用console.groupEnd()關閉塊。該命令可以嵌套使用。

console.groupEnd()
關閉最近一個由console.group開啟的塊。

console.time(name)
建立一個名字為name的計時器,調用console.timeEnd(name)停止計時器並輸出所耗時間(毫秒)。

console.timeEnd(nam

js輸出到控制台

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.