customizing JavaScript Debug output functions

Source: Internet
Author: User

Defines two functions, PT output expression and its computed result, put output string:

<span id= "DBG" >     
<b> Debugging Information:</b>     
</span>     
        
<script language= "JavaScript" >     
function pt (myexp) {     
    document.getElementById ("dbg"). innerhtml+= "<br>&nbsp;&nbsp;&nbsp ;&nbsp; " +myexp+ "&nbsp;&nbsp; <font color= #0000C6 > "+eval (myexp). toString () +" </font> ";     
}     
function put (mystr) {         
    document.getElementById ("dbg"). innerhtml+= "<br>&nbsp;&nbsp;&nbsp; &nbsp;<font color= #0000C6 > "+mystr+" </font>;     
}     
</script>

Use case:

<script language= "javascript" >     
    function IsObject (myVar) {
        if (MyVar && typeof myvar=== "Object") {return
            true;             
        } else{return
            false;     
        }     
        
    var a= "B";     
    Switch (a) {case     
        ' a ': put ("Switch A");     
        Case "B": Put ("Switch B");     
        Case "C": Put ("Switch C");     
        Default:put ("switch Default");     
        
    PT ("typeof/a/");     
    PT ("typeof null");     
    PT ("IsObject (/a/)");     
    PT ("IsObject (null)");     
    PT ("0.1+0.2");     
    PT ("isNaN (NaN)");     
    PT ("typeof/a/");     
    PT ("1==true");     
    PT ("1===true");     
</script>

The output screenshot is as follows:

How is it, isn't it convenient? To obtain the full source code, please download the attachment and recommend renaming to the *.html file.

This article is from the "idata" blog, please be sure to keep this source http://idata.blog.51cto.com/4581576/1100061

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.