js物件導向學習筆記之二(debug調試方法)

來源:互聯網
上載者:User

js物件導向學習筆記之二(debug調試方法)

1. js的調試

 

很明顯,js 調試只能夠通過 alert 進行列印

alert(id);


對於複雜的資料類型,我們可以通過將其轉換成json格式 再進行彈出
alert(JSON.stringify(data));



2. DOM 資訊調試
對於我們需要擷取到的資訊 可以根據要求列印到dom元素裡

document.write(data); //會覆蓋整個文檔



3. 在程式端調試
直接在程式端列印所需資訊後退出
var_dump()print_r()




4. js 其他錯誤資訊處理
/*==================大多數瀏覽器支援 有少部分不支援=====================*/window.onerror=handleErrfunction handleErr(msg,url,l){    txt="There was an error on this page.\n\n"    txt+="Error: " + msg + "\n"    txt+="URL: " + url + "\n"    txt+="Line: " + l + "\n\n"    txt+="Click OK to continue.\n\n"    alert(txt)    return true;}

5. try catch 調試

/*==================瀏覽器都支援====================*/    try{      adddlert("Welcome guest!");    }    catch(err){          txt="本頁有一個錯誤。\n\n";          txt+="錯誤描述:" + err.message + "\n\n";          txt+="點擊確定繼續。\n\n";          alert(txt);   }



6. 當然我們如果在 PC端瀏覽器上檢查錯誤可以使用 console.log
console.log(data);







聯繫我們

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