JavaScript Simple Application

Source: Internet
Author: User

JavaScript Simple Application

A: Introduction

This note is a summary and focus on the content of chapter 4th of the JavaScript authoritative guide. Not reproduce the book instance. Most of the examples in the book are on GitHub and are interested in reading the book or GitHub code. The GitHub address is placed in the JavaScript directory.

II: JavaScript Application steps

1. Writing JavaScript scripts

2. Reference in the page:

A) JavaScript-related content can be placed directly on the page using the <script> tag.

b) The script can be placed in one or more files with the end of JS file, in the need to use the page to introduce.

Three: Case brief

When there are multiple links in the Web page, when no links are clicked, the display location below the page displays a default picture and default description, replaces the default picture of the location shown below with a link-directed image, and displays the link's description at the specified location when a specific link is clicked.

Four: example implementation key points

1. Get the Herf and title properties of the A link.

2. Add a click event for all links.

3. Block link default behavior.

2. Modify the text content within the SRC and description tags of the default picture label.

Five: Related methods and solutions

1. Block a default behavior:

<li><a onclick= "switchpicture (this); return false "href=". /picture/chenhong.jpg "title=" Chen Hong ">chen hong</a></li>

2. Related methods

function Switchpicture (whichpicture) {var Source = Whichpicture.href;var placeholder = document.getElementById (' Placeholder ');p laceholder.setattribute (' src ', source);d Ocument.getelementbyid (' description '). Firstchild.nodevalue = Whichpicture.getattribute (' title ');}

VI: Supplement

Effect:

Showpicture.js:

function Switchpicture (whichpicture) {var Source = Whichpicture.href;var placeholder = document.getElementById (' Placeholder ');p laceholder.setattribute (' src ', source);d Ocument.getelementbyid (' description '). Firstchild.nodevalue = Whichpicture.getattribute (' title ');} /* Function Countbodychildren () {Alert (document.getElementsByTagName (' body ') [0].childnodes.length);} window.onload = countbodychildren;*/

Showpicture.html:

<! DOCTYPE html>

SHOWPICTURE.CSS:


Body {font-family: "Helvetica", "Arial", Serif;color: #333; Background-color: #ccc; margin:1em 10%;} h1 {color: #333; background-color:transparent;} A {color: #c60; background-color:transparent;font-weight:bold;text-decoration:none;} UL {padding:0;} Li {float:left;padding:1em;list-style:none;} img {display:block;clear:both;}


JavaScript Simple Application

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.