Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the knowledge points of javascript?

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

What are the knowledge points of javascript? in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.

I. basic introduction to JavaScript

Js was born in 1995, is the abbreviation of Javascript, it has nothing to do with the java language, the main purpose at that time is to verify whether the data in the form is legal

Popular science: Javascript was supposed to be called livescript, but on the eve of its release, I temporarily changed its name to javascript in order to catch a ride with the media super-hot java. (that is to say, js has nothing to do with java, it just wanted to take advantage of java's fame at that time.)

Role: responsible for controlling the first two of the web front-end standard. Structure and style

For example, the arrow switches the picture page, and so is the point in the lower left corner.

No js: there is no js page, and it is very troublesome to submit information accurately.

ANS:js was born to verify the validity of the form data, js is to add validation to it, if the input is completed, it will be passed, and if it is not correct, it will prompt for an error. Js is to solve this problem.

Today, js can not only do verification, but also do website special effects.

II. Basic grammar of Javascript

1. Write the script tag and put it at the end of the html page. The js code is written in the script tag in html.

two。 From the middle of the script tag, alert ("pop-up content, whatever is written here will pop up")

Alert ("display in pop-up windows")

Pop-up warning box, pop-up dialog box:

Alert ()

Alert ('attention: pop-up window')

Note: the alert dialog box that comes with the browser cannot be unified. These are all built-in at the bottom of the browser and cannot be modified.

III. JavaScript event

Definition: under what circumstances and what commands are executed

Function: capture the user's behavior (click, double click, move in and out of the mouse. .. )

Example 1: when clicking, switch the interface and execute the command under what circumstances.

Three elements of the event:

Three elements of an event: the source of the event. Type of event = command executed

1. Event source: "the explanation is to whom this event is added)

two。 Event type: (that is, when did this event occur)

3. Instruction executed: fixed function (H your command is written here} event source "dot event name = anonymous function (anonymous method)

Example 2: when clicking on the div tab, do one thing, such as click and pop up the dialog box. -- using the id class / / Click div on the page, pop-up dialog box / / first step: if you want to control a tag, you must first find it, use the selector in css to find it. Js finds the document on the current page / / step 2: click div / / step 3: pop-up dialog box document.getElementById ('div1'). Onclick=function () {alert (' when you click, it pops up') } / / three elements of an event: the event source. Type of event = command executed

Example 3: add the tag p, use the class class to , I am the p1 tag

I'm the p2 tag.

/ / Click div on the page, pop-up dialog box / / first step: if you want to control a tag, you must first find it, use the selector in css to find it. Js finds the document on the current page / / step 2: click div / / step 3: pop-up dialog box document.getElementById ('div1'). Onclick=function () {alert (' pop-up only when you click div') } / / three elements of an event: the event source. Type of event = command document.getElementsByClassName ('p1') [0] .ondblclick = function () {alert (' pop up only when p is clicked');} / / getElementsByClassName finds elements in the page through class, while class can set multiple duplicate class names / / then [0] must be added after the acquisition, counting from the number 0

Note:

Id is unique, that is, single

While class is a class, it is plural. In js, you can use getElementsByClassName to find the elements in the page through class, while class can set multiple duplicate class names, so you must add [0] after the acquisition, counting from the number 0.

Test points:

1. Pop-up dialog box not clicked

2. Click the dialog box that does not pop up

4. Javascript writing position (introduction mode) 4.1 embedded js

Embedded js: in the html file. Put it in the scipt tag, that is, write it in the html and put it in the script tag, which is called embedded.

Alert ("display in pop-up windows")

Example:

Alert ('pop-up window embedding')

4.2 Outer chain js

Outer link js: it can be referenced to the page through the src attribute in the script tag in a separate js file; that is, it is written in a separate js file and linked to the html page through the src in script, which is called outer link.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report