Original address: http://blog.csdn.net/jom_ch/article/details/864574
Usually we do a simple JS debug output when used to use the alert function, this function can also solve most problems, but encountered such as cyclic output, scroll bar status monitoring, mouse position and other scenes, alert is quite inconvenient, the following function can solve the problem:
[JavaScript]View Plaincopy
- <script type="Text/javascript" >
- function __js_debug_msg () {
- var mydiv = document.createelement (' div ');
- Mydiv.id = "Js_debug_msg";
- Mydiv.setattribute (' style ',' position:fixed;width:300px;height:40px;padding:5px;background: #333; Line-height:20px;color: #FFF; margin-top:0px;top:0px;right:0px; ');
- Mydiv.innerhtml="Print JS debug message.";
- Document.body.appendChild (MYDIV);
- }
- __js_debug_msg ();
- </script>
Put the above code at the bottom of the page where you need to output debugging information, and then use the innerHTML code alert when you need to output debugging information, such as:
[JavaScript]View Plaincopy
- document.getElementById (' js_debug_msg '). InnerHTML = ' information required for output ';
with Jqeury words:
[JavaScript]View Plaincopy
- $ (' #js_debug_msg '). HTML (' information that needs to be output ');
You can also output error messages
[JavaScript]View Plaincopy
- <script type="Text/javascript" >
- Need to be placed on the head of the page, such as the head area
- Window.onerror = function (err_msg, filename, line_num) {
- document.getElementById (' js_debug_msg '). InnerHTML = ' error message: ' +err_msg+' |line: ' +line_num+' | File: ' +filename;
- return false;
- }
- </script>
"Turn" JS debugging information Output Tips