Js object-oriented learning note 2 (debug debugging method)
1. js debugging
Obviously, js debugging can only be printed through alert
alert(id);
For complex data types, we can convert them to json format before the pop-up
alert(JSON.stringify(data));
2. DOM information debugging
The information we need to obtain can be printed to the dom element as required.
Document. write (data); // overwrites the entire document
3. Program-side debugging
Print the required information directly on the program end and exit.
var_dump()print_r()
4. Handle other js error messages
/* =============================Most browsers support a small portion of =========== */window. onerror = handleErrfunction handleErr (msg, url, l) {txt = "There was an error on this page. \ n "txt + =" Error: "+ msg +" \ n "txt + =" URL: "+ url +" \ n "txt + =" Line: "+ l +" \ n "txt + =" Click OK to continue. \ n "alert (txt) return true ;}
5. try catch debugging
/* = === */Try {adddlert ("Welcome guest! ");} Catch (err) {txt =" An error occurred on this page. \ N "; txt + =" error Description: "+ err. message +" \ n "; txt + =" click "OK" to continue. \ N "; alert (txt );}
6. Of course, you can use console. log if an error occurs in the PC browser.
console.log(data);