Js object-oriented learning note 2 (debug debugging method)

Source: Internet
Author: User

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);







Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.