In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "how to achieve regular advertising in JavaScript". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1. Overview of JavaScript 1.1 what is JavaScript
JavaScript is a powerful programming language on web for developing interactive web pages. It does not need to be compiled, but is directly embedded in the HTML page and executed by the browser.
JavaScript is designed to add interactive behavior to HTML pages.
JavaScript is a scripting language (scripting language is a lightweight programming language).
JavaScript consists of several lines of executable computer code.
JavaScript is usually embedded directly into HTML pages.
JavaScript is an interpretive language (that is, code execution is not precompiled).
The composition of JavaScript:
Core (ECMAScript)
Document object Model (DOM)
Browser object Model (BOM)
ECMAScript: syntax, statement.
BOM: browser object.
DOM:Document Object Model. Manipulate the elements and contents of the document.
1.2 the role of JavaScript
Use JavaScript to add page animation effects to provide user experience. The main applications are: embedding dynamic text in HTML pages, responding to browser events, reading and writing HTML elements, verifying submitted data, detecting browser information of visitors, and so on.
1.3introduction of JavaScript
There are two ways to introduce JavaScript into HTML files, one is to embed JavaScript scripts directly in HTML documents, which is called embedded, and the other is to connect external JavaScript script files, called outer chained ones. The specific explanation to them is as follows:
(1) embedded, introduced through tags in HTML documents, as follows
/ / here is the JavaScript code
(2) external connection, in the HTML document, introduce the .js file through the tag, as follows:
two。 Basic Syntax 2.1 variables
(1) when using JavaScript, you need to follow the following naming conventions:
Must start with a letter or underscore, which can be a number, character, or underscore
Variable names cannot contain symbols such as spaces
You cannot use the JavaScript keyword as the variable name, such as: function
JavaScript is strictly case-sensitive.
(2) declaration of variables
Var variable name; / JavaScript variable can be used without declaration. Default value: undefined
(3) assignment of variables
Var variable name = value; / / JavaScript variable is weakly typed, and the same variable can hold different types of data 2.2 data types
[basic type]
The Undefined,Undefined type has only one value, undefined. When a declared variable is not initialized, the default value for that variable is undefined.
Null, which has only one private value, null, is empty and has a placeholder. The value undefined is actually derived from the value null, so ECMAScript defines them as equal.
Alert (null = = undefined); / / outputs "true", although the two values are equal, but they have different meanings.
Boolean, which has two values, true and false
Number, which represents any number
String, a string declared by double quotation marks (") or single quotation marks ('). JavaScript has no character type
Calling the typeof operator on a variable or value returns one of the following values:
Undefined- if the variable is of type Undefined
Boolean- if the variable is of type Boolean
Number- if the variable is of type Number
String- if the variable is of type String
Object- if the variable is of a reference type or Null type
[reference type]
A reference type is usually called a class, that is, when you encounter a reference value, you deal with an object.
JavaScript is object-based rather than object-oriented. The default value for object types is null.
JavaScript provides many predefined reference types (built-in objects).
2.3 operator
The JavaScript operator is basically the same as the java operator. You can read my basic essays on java.
2.4 basic operation
Alert (): a prompt box pops up to the page!
InnerHTML: write a paragraph to an element of the page to overwrite the original
[xss_clean] (): write content to the page
2.5 the way functions are written in js:
Function: a block of code that implements a certain function, similar to the method in java. Keyword function, custom function name.
/ / Mode 1: declare function function demo01 () {alert ("case 1");} / / Mode 1: call function demo01 (); / / Mode 2: declare anonymous function var demo02 = function () {alert ("case 2") }; / / Mode 2: call function demo02 (); 3. Example: broadcast figure 3. 1 timer setIntervalwindow.setInterval (code,millisec) executes a function or code snippet according to a specified period (interval). The parameter 1:code must be. The name of the function executed or the code string executed. The parameter 2:millisec must be. Time interval, in milliseconds. Return value: a value that can be passed to window.clearinIerval () to cancel periodic execution of code. For example, mode 1: function name, setInterval (show, 100); mode 2: function numeric string, setInterval ("" show (), 100)
The window object provides global functions that window can be omitted when calling functions.
Window.setInterval () equivalent setInterval ()
3.2 case implementation
Step 1: add an id attribute to the img tag of the broadcast map
Step 2: write the js code, and the page load triggers the specified function
/ / load successfully to start the listener, execute _ window.onload = function () {setInterval (changeImage, 2000)} / / switch between 3 photos var num = 1; function changeImage () {if (num > = 3) {num = 1;} var imageobj = document.getElementById ("imgId") Imageobj.src = "img/" + num++ + ".jpg"} 4. Case: timed bullet advertisement 4.1timer: setTimeout
SetTimeout () calls a function or executes a code snippet after the specified number of milliseconds.
SetTimeout (code,millisec) code is required. The function to call or the code string to execute. Millisec is required. The number of milliseconds to wait before executing the code.
SetInterval () executes a function or code snippet in a specified period.
ClearInterval () cancels the timeout set by setInterval ().
ClearTimeout () cancels the timeout set by the setTimeout () method.
4.2 JavaScript style obtained or modified
Get or set the style
Obj.style. Property to get the value of the specified property. Obj.style. Property = value to the specified property setting content. If the attribute is connected by multiple words with "-", you need to delete the "-" and capitalize the first letter of the last word. For example: background-color needs to be changed to backgroundColor
Example:
Small gray / / 1 get div object var divObj = document.getElementById ("divId"); / / 2 get height / / divObj.style.height data as "100px" / / use parseInt () to convert the string "100px" into the number "100" var height = window.parseInt (divObj.style.height) / / 3 double the original height and then set it to div. DivObj.style.height = height * 2 + "px"
4.3 case implementation
Step 1: in the page, add the ad space div and set the page load event
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.