Home Web Front-end JS Tutorial JavaScript Basics Chapter 1 JavaScript and Client_Basic Knowledge

JavaScript Basics Chapter 1 JavaScript and Client_Basic Knowledge

May 16, 2016 pm 06:22 PM
js Base

One page output
1. Header file

Copy code The code is as follows:

< ;head>


2. Copy the code within the page
The code is as follows:


<script> <br>document.write("Script Home"); <br></script>


3. External file

4. InnerHtml using page ID
Copy code The code is as follows:

<script> <br>window.onload = writeMessage; // Call the writeMessage function when the page is loaded<br>writeMessage( ) { <br>document.getElementById("helloMessage").innerHTML = "Script Home"; <br>//Find the dom ID (helloMessage) and modify its html content<br>} <br></script>

5. Warning
alert("Guangzhou Baihui Logistics Co., Ltd.");
6. Inquiry
Copy code The code is as follows:

if (confirm("Do you want to visit our homepage"))
{
alert("Yes, go to") ;
}
else {
alert("Exit");
}

7. Enter
Copy code The code is as follows:

var ans = prompt("Enter your message","Hello,");
if (ans) {
alert("You said:" ans);
}
else {
alert("Exit, no message");
}

8. Page jump Transfer
Copy code The code is as follows:

<script> <br>window.onload = initAll; <br>function initAll() { <br>document.getElementById("redirect").onclick = initRedirect; <br>} <br>function initRedirect() <br>{ <br>window.location = "index .html"; <br>return false; <br>} <br></script>
Script of Home

9. Judgment branch
Copy code The code is as follows:

<script> <br>window.onload = initAll; <br>function initAll() { <br>document.getElementById("Lincoln").onclick = saySomething; <br>document.getElementById ("Kennedy").onclick = saySomething; <br>document.getElementById("Nixon").onclick = saySomething; <br>} <br>function saySomething() { <br>switch(this.id) { <br>case "Lincoln": <br>alert("Four score and seven years ago..."); <br>break; <br>case "Kennedy": <br>alert("Ask not what your country can do for you..."); <br>break; <br>case "Nixon": <br>alert("I am not a crook!"); <br>break; <br>default: <br>} <br>} <br></script>


type="button" id="Kennedy" value="Kennedy" />
value="Nixon" />


10. Exception catching
Copy code The code is as follows:

window.onload = initAll;
function initAll() {
var ans = prompt("Input parameters: ","");
try {
if (!ans || isNaN(ans) || ans<0) {
throw new Error("The input is not a number");
}
alert("root sign" ans " yes " Math.sqrt(ans));
}
catch (errMsg) {
alert(errMsg.message);
}
}
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use JS and Baidu Maps to implement map pan function How to use JS and Baidu Maps to implement map pan function Nov 21, 2023 am 10:00 AM

How to use JS and Baidu Maps to implement map pan function

Essential tools for stock analysis: Learn the steps to draw candle charts with PHP and JS Essential tools for stock analysis: Learn the steps to draw candle charts with PHP and JS Dec 17, 2023 pm 06:55 PM

Essential tools for stock analysis: Learn the steps to draw candle charts with PHP and JS

Recommended: Excellent JS open source face detection and recognition project Recommended: Excellent JS open source face detection and recognition project Apr 03, 2024 am 11:55 AM

Recommended: Excellent JS open source face detection and recognition project

PHP and JS Development Tips: Master the Method of Drawing Stock Candle Charts PHP and JS Development Tips: Master the Method of Drawing Stock Candle Charts Dec 18, 2023 pm 03:39 PM

PHP and JS Development Tips: Master the Method of Drawing Stock Candle Charts

How to create a stock candlestick chart using PHP and JS How to create a stock candlestick chart using PHP and JS Dec 17, 2023 am 08:08 AM

How to create a stock candlestick chart using PHP and JS

How to use JS and Baidu Maps to implement map polygon drawing function How to use JS and Baidu Maps to implement map polygon drawing function Nov 21, 2023 am 10:53 AM

How to use JS and Baidu Maps to implement map polygon drawing function

How to use JS and Baidu Map to implement map click event processing function How to use JS and Baidu Map to implement map click event processing function Nov 21, 2023 am 11:11 AM

How to use JS and Baidu Map to implement map click event processing function

How to use JS and Baidu Maps to implement map heat map function How to use JS and Baidu Maps to implement map heat map function Nov 21, 2023 am 09:33 AM

How to use JS and Baidu Maps to implement map heat map function

See all articles