非常好用的前端調試函數console.log(),chromeconsole調試

來源:互聯網
上載者:User

非常好用的前端調試函數console.log(),chromeconsole調試

使用console.log這個函數對於前端的調試非常好用,但是它的使用要依賴於瀏覽器,我們可以利用這個函數來測試我們的資料是數組,字串,對象還是其它類型資料,這樣極大方便了我們的調試

以下是我的測試例子

<html><head><script>function test(){var username = document.getElementsByName("username");console.log(username);var username1 = document.getElementsByName("username")[0].value;console.log(username1);var username2 = document.getElementsByName("username")[1].value;console.log(username2);var username3 = document.getElementsByName("username").value;console.log(username3);}</script></head><body><input type="text" name="username"><br><input type="text" name="username"><input type="button" onclick="test()"><body></html>

然後我們用瀏覽器進行訪問,出現如下結果

我們任意輸入資料,我這裡輸入了 1312和1w12w,按一下鍵盤的F12調出瀏覽器開發人員工具,點擊按鈕測試

出現如下結果


這時我們可以在控制台看到我們資料的結構,第一行是一個對象列表,就是數組,數組的每個元素是一個input

二三行則是input裡的資料

第三行是我故意這樣測試,這樣可以看出錯誤

所以利用這個函數是非常方便的,便於我們分析前端的資料

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.