Some skills you need to know in JS (DHTML)_Basic knowledge
There are no update logs these days, so this article can be regarded as talking about some of my own experiences. I will briefly share some tips with you. I hope it will be helpful to you. If you still have any questions, you can leave a message below.
1. Congruence operator
In JS, all numbers that are not 0 are true, except for a few special variables. For example: undefined, null, "", etc. This is what we expect in most cases.
But you should not ignore this equality operator. Therefore, if more stringent effects are needed, we can use the congruence operator ===, see the following code:
//Some common effects
var foo = function(arg) {
if ( !arg) {
alert("normal false");
} else { alert("true"); }
}
foo(null); //false
foo(false ); //false
foo(""); //false
foo("never-online"); //true
//Congruent effect
var foo = function(arg) {
if (arg===false) {
alert("false");
} else { alert("not a false variable") }
}
foo(null) ; //not a false variable
foo(false); //false
foo(""); //not a false variable
foo("never-online"); //not a false variable
2. One of the applications of variables - removing web page nesting
For example, if you want to embed baidu.com into an iframe of your own, the result you get is not What you want, because it has such a code
if(self!=top){top.location=self.location;}
The meaning of this code is: if the web page is nested (that is, If frame technology is used, the nesting will be removed and the URL in the frame will be given to the top-level window)
This is a headache. For example, the above code is also used in some free spaces. What if it is removed? Use this code to remove nesting:
The following explains why using this code can remove nesting:
We know that in JS variables, if the variable is like this
can display the string "never-online". And when you restore the sentence //var myVar (that is, when you don't comment it out) the result is different and undefined will be displayed. The same is true when we use var location="never-online". The following code may solve your doubts.
Similarly, when running for the second time, restore the var location sentence, and you should understand the reason after comparing it. The same is true for windows and documents. If you are interested, you can try it.
3. Get the path of the current page
To achieve this goal, there are many ways, such as using the location object, but the example I give here is to use an IMG tag created . Look at the code:
As we know, "." in the path represents the current folder. Therefore, using IMG to obtain the path can obtain the path faster in some cases.
4. Use the !! operator to get the boolean value of a variable. To a certain extent, it is equivalent to forced transformation
For example,
Why is this happening? We can get the answer from Tip 1. It will not be repeated here.
5. Conditional compilation.
You can use this method if you feel it is necessary. This is similar to conditional compilation in some strong languages. In many cases it is used for - compatibility.
This is just a brief mention. If you are interested, you can refer to MSDN or read some articles about JS conditional compilation.
Only a few syntaxes are needed:
@cc_on - This sentence is required in conditional compilation, indicating that conditional compilation is activated
@set @varname = term - This sentence is for assignment
Here below It’s just a matter of judgment
@if
@else
@end
Simple example:
/*@cc_on
document.write("JScript version: " @_jscript_version ".
");
/*@if (@_jscript_version >= 5)
document.write("JScript version 5.0 .
");
document.write("Only if the browser supports You can only see these texts when using JScript5.
");
@else @*/
document.write("When you use other browsers (such as: Firefox, IE 4.x, etc.) When I saw this line of text <script> <BR>var location='never-online'; <BR></script>"); <script> <BR> //<![CDATA[ <BR> myVar = "never-online"; <BR> (function () { <BR> //var myVar; <BR> alert(myVar) <BR> })() <BR> //]]> <BR> </script> /*@end <script> <BR> //<![CDATA[ <BR> alert(location); <BR> //var location; <BR> //]]> <BR> </script>@*/ <script> <BR> //<![CDATA[ <BR> var p = document.createElement("IMG"); <BR> p.src="."; alert(p.src); <BR> //]]> <BR> </script><script> <BR> //<![CDATA[ <BR> var isSupportedXMLHttp = !!new ActiveXObject("MSXML2.XMLHTTP"); <BR> alert(isSupportedXMLHttp) <BR> //]]> <BR> </script> 6. Others, I can’t think of so many right now, so I’ll just write them here for now.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

JavaScript is the core language of modern web development and is widely used for its diversity and flexibility. 1) Front-end development: build dynamic web pages and single-page applications through DOM operations and modern frameworks (such as React, Vue.js, Angular). 2) Server-side development: Node.js uses a non-blocking I/O model to handle high concurrency and real-time applications. 3) Mobile and desktop application development: cross-platform development is realized through ReactNative and Electron to improve development efficiency.

This article demonstrates frontend integration with a backend secured by Permit, building a functional EdTech SaaS application using Next.js. The frontend fetches user permissions to control UI visibility and ensures API requests adhere to role-base

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.
