Simple JavaScript applications and javascript applications

Source: Internet
Author: User

Simple JavaScript applications and javascript applications
Simple JavaScript Application

 

I. Introduction

 

This note is a summary and key record of Chapter 4th of the JavaScript authoritative guide. It is not a reproduction of book instances. Most of the examples in the book are stored on github. If you are interested, you can read this book or the Code on github. The github address is stored in the JavaScript directory.

 

Ii. JavaScript Application steps

 

1. Write JavaScript scripts

2. Reference in the page:

A) You can directly use the <script> tag on the page to add JavaScript-related content.

B) You can add the script to one or more files ending with JavaScript and introduce the script on the desired page.

 

 

Iii. instance description

 

When a webpage contains multiple links and no links are clicked, a default image and default description are displayed at the bottom of the page. When a specific link is clicked, the default image at the bottom is replaced. link to the image, and display the description of the link at the specified position.

 

Iv. Key Points of instance implementation

 

1. Obtain the herf and title attributes of the link.

2. Add a click event for all links.

3. Block the default link behavior.

2. Modify the src of the default image label and the text content in the description label.

 

V. Related methods and Solutions

1. prevent a's 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');placeholder.setAttribute('src', source);document.getElementById('description').firstChild.nodeValue = whichPicture.getAttribute('title');}

Vi. Supplement

 

Effect:

 

ShowPicture. js:

function switchPicture (whichPicture) {var source = whichPicture.href;var placeholder = document.getElementById('placeholder');placeholder.setAttribute('src', source);document.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;}


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.