Home >Web Front-end >JS Tutorial >Introductory knowledge of js
Introductory knowledge of js
1. What is js? HTML writes the structure, css writes the style, and js writes the element behavior to interact with the user, making the page more intelligent and understanding me better
2.js is a client-side scripting language. It is written directly to the current HTML page for execution and does not require server environment support.
2. Like css, there are three ways to introduce js into In the current html document:
2-1: In the tag event attributes: onclick, onmouseover...
2-2: Write to '3f1c4e4b6b16bbbd69b2ee476dc4f83ajs code72534d8f75a0cd804f60d21c01b78a79f9d4d9631f6ee33ccc8e3d2bd859bba5 to import
3. Key points: Where should the js code written using the 3f1c4e4b6b16bbbd69b2ee476dc4f83a tag be placed in the page?
3-1: It can be placed in the 93f0f5c25f18dab9d176bd4f6de5d30e
3.2: Can be placed in 6c04bd5ca3fcae76e30b72ad730ca86d
3.3: Can even be placed outside the 100db36a723c770d327fc0aef2ce13b1 tag
So it doesn’t matter where the js code is placed, it will be The page is loaded and executed
4. Variables:
4-1: Declare var name='peter'
4-2: If no var declaration is used, it will automatically become Properties of the global object window, this is not recommended
5. Type:
5-1: Five basic types: Number, String, Boolean, Undefined, Null
5-2: Three object types: Object, Array, Function
5-3: Type detection typeof
6. Basic operations:
6-1: Arithmetic Operations: ,-,*,/, %
6-2: String concatenation:
6-3: Comparison operations: 6580843315dd7804e35fd3743df832ea,==...
6-4: Assignment: =
6-5: Logic operation: &&, || , !
7. Language structure:
7-1 : Conditional judgment: if, if~else, if~else if, switch, ternary
7-2: Loop: while, do~while, for()
8. Scope : js is the same as php, there is no block scope, only function scope and global scope, any variable or function must belong to one of them
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>js的入门知识</title> <!-- <script type="text/javascript">alert('hello php中文网')</script> --> </head> <body> <a href="../images/zly.jpg">查看我的相片</a> <script type="text/javascript"> function show(pic){ window.open(pic.href,'','width=300,height=300,top=100,left=200') } </script> <script type="text/javascript"> var obj = document.getElementsByTagName('a')[0] obj.onclick = function (){ window.open(this.href,'','width=300,height=300,top=100,left=200') return false } </script> </body> </html>
The above is the detailed content of Introductory knowledge of js. For more information, please follow other related articles on the PHP Chinese website!