Home >Web Front-end >JS Tutorial >Some common problems and debugging techniques in client scripts_Basic knowledge

Some common problems and debugging techniques in client scripts_Basic knowledge

WBOY
WBOYOriginal
2016-05-16 19:21:341279browse
1. Error situation: Syntax error



Explanation: The above example is a typical example, and the method name must be enclosed in () () are parameters.
Maybe some people are dismissive, but in the forum. This kind of mistake is not uncommon.
Tips: This kind of problem is relatively simple to solve and can generally be solved.

2. Error: Incorrect usage of quotation marks



Explanation: In javascript or vbscript programming, the probability of quotation mark errors is very high. No matter how rich your programming experience is, if you encounter a large number of string concatenations or accidentally type the wrong '("), "grammar errors" or "missing '" will appear.
Tips: In progress When splicing a large number of characters, you need to pay attention to the escaping usage of quotation marks. For example, it can be written as: s="alert("never-online")"; or s='alert("never-online")';
Related links: js skills - the wonderful use of escape character "" - http://blog.csdn.net/bluedestiny/archive/2006/03/15/625061.aspx
3. Error situation: Unknown soft error




is run and no error is prompted. This gives people the illusion that soft errors like this are difficult to find. .
So you must be careful when writing programs. Tips: You should pay attention to your own habits when programming. For example, if you use { in for(var i=0;i
is probably the this keyword. Here is an example to illustrate the semantics of
this:
Example:

<.>I believe that in the above example, many people understand that this points to a()
Look at the following example:
div container - onmouseover handle



Some brothers may not understand this example. After taking a closer look, you can also predict the output result.
Explanation: this.m = val = 'never-online' is an assignment, and this.m in it. This in div.onmouseover points to the current object a();
and this in div.onmouseover refers to the object document.getElementById("div1") (because div does not belong to the a object), which is equivalent to The code is written here:
div container - onmouseover handle
<script> <BR>document.write("never-online"; <BR></script>So it is not surprising that this.m appears undefined in the function of div.onmouseover.​
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn