ps: since the author plans to develop to the java back-end in the future, he only understands some of the main contents of the front-end knowledge, focusing on applications. Therefore, if there are errors, please correct them in time!
JS is an event driven programming language, which relies on events to drive, and then executes the corresponding program;
Take the click event as an example;
Each event will have a corresponding event handle. For example, in this click example, the event handle is onclick
Note: the difference between an event and an event handle is that an on is added before the event word
Moreover, the event handle exists as the attribute of HTML tag;
So the function of our example is: the user clicks the following button to pop up a message box
So how to pop up a message box by clicking the button?
In JS, there is a built-in object called window, which is all lowercase and can be used directly. Window represents the browser object;
The window object has a function called alert. The usage is: window.alert("message"); So you can pop up the window;
Examples are as follows:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>HTML Embedded in JS The first way to code</title> </head> <body> <input type="button" value="hello" onclick="window.alert('hello zhangsan') window.alert('hello lis') window.alert('hello wangwu')"/> <!-- window. Can be omitted.--> <input type="button" value="hello" onclick="alert('hello zhangsan') alert('hello lis') alert('hello wangwu')"/> </body> </html>
This method is similar to and simple to the internal CSS styles mentioned in the previous CSS summary
The format is:
Examples are as follows:
Import external independent js files
In order to better separate the HTML page from the js script, you can save the js script separately into a *. js file, and then import it in HTML,
Again: the end < / script > must be, otherwise the page will not be displayed!
Another point: we must pay attention to the distinction. We introduce a file link in CSS, using a href = "URL (unified resource locator)"
JS uses SRC = "URL (uniform resource locator)"
window.alert("hello js!"); window.alert("hello js!"); window.alert("hello js!"); window.alert("hello js!"); window.alert("hello js!"); window.alert("ending");
Summarize these three points:
- Event Handler
- Script block
- Import external independent js files
Compared with CSS and HTML, JS has a lot of content, which is just a starting point. I hope we can cheer together!
Welcome your comments!