This article mainly through an adder, introduced JS how to Debug. First code:
Effect:
Test.html:
<span style= "Font-family:comic Sans ms;font-size:18px;" ><! DOCTYPE html>
Demo.js
<span style= "Font-family:comic Sans ms;font-size:18px;" >/**
* Created by Yanzi on 15/12/8.
* *
var num1 = document.getElementById ("Num1"),
num2 = document.getElementById ("num2"), result
= document.getElementById ("result"),
Btn_add = document.getElementById ("add");
Btn_add.addeventlistener ("Click", Onaddclick, false);
function Onaddclick () {
var a = parseint (Num1.value),
B = parseint (num2.value);
var sum = Add (a, b);
result.innerhtml = sum;
}
/**
*
@param a
* @param b
* @returns {*}
/function Add (A, b) {return
a+b;
} </span>
Summary of Highlights:
1, General debugging JS, printing information has the following three kinds:
A. With alert, the disadvantage is that every time the bomb frame
B. With Console.log, this is a small amount of data can also
C. Add Breakpoint Debugging
2, in JS, if the variable preceded by Var, representing local variables, function if the global variable without var. Therefore, in general, the variable is preceded with Var.
3, generally in the Chrome debugger, elements look at the code, in the source directory for debugging. In this mode, click on each line in JS can be added breakpoints.
4, debugging mode, the rightmost four buttons are: The next breakpoint, step into the next function, jump out of the function. Basically all of the debugging tools have these four kinds.
5, in the breakpoint mode, input variables in the console can see the current value, at the same time you can modify the value.
The above is the specific steps of JS debugging, I hope everyone in JavaScript programming will use JS for debugging, thank you for your reading.