JavaScript Basics Chapter 1 JavaScript and Client_Basic Knowledge
One page output
1. Header file
< ;head>
2. Copy the code within the page
<script> <br>document.write("Script Home"); <br></script>
3. External file
4. InnerHtml using page ID
<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
if (confirm("Do you want to visit our homepage"))
{
alert("Yes, go to") ;
}
else {
alert("Exit");
}
7. Enter
var ans = prompt("Enter your message","Hello,");
if (ans) {
alert("You said:" ans);
}
else {
alert("Exit, no message");
}
8. Page jump Transfer
<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
<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>
10. Exception catching
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);
}
}

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

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

Recommended: Excellent JS open source face detection and recognition project

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 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 Maps to implement map heat map function
