childNodes property: 
The childNodes property is a way of getting information about the children of any element in a 
document's node tree. It returns an array containing all the children of an element node :
    element.childNodes; 
 
Lets say you wanted to get all the children of the body element.
    var body_element = document.getElementsByTagName("body")[0];
To access the children of the body element, you just need to use :
    body_element.childNodes; 
you may write a function to find out how many elements the body element contains :
 function countBodyChildren() {
var body_element = document.getElementsByTagName("body")[0] ;
alert( body_element.childNodes.length );
}
If you want this function to be excuted when the page loads, you can use the onload event handler
to do this. 
        window.onload = countBodyChildren ;
When the document loads, the countBodyChildren function will be invoked.
 

 
nodeType property :
This will tell us exactly what kind of node we're dealing with. 
The nodeType property is called with the following syntax : 
node.nodeType
instead of returning a string like "element" or "attribute", it returns a number.
There are 12 possible values for nodeType, but only 3 of them are going to be of much practical use:
  • Element nodes have a nodeType value of 1
  • Attribute nodes have a nodeType value of 2
  • Text nodes have a nodeType value of 3
 

 
nodeValue property :
If you want to change the value of a text node, there is a DOM property called nodeValue that can be 
used to get (and set) the value of a node :
node.nodeValue
 
firstChild and lastChild property :
node.firstChild  ==  node.childNodes[0]
node.lastChild   ==  node.childNodes[node.childNodes.length-1]
 

This image gallery projects are as follws :
/***      index.html      ***/
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Image Gallery</title>
<link rel="stylesheet" href="styles/layout.css" media="screen">
</head>
<body> <h1>Snapshiots</h1>
<ul>
<li>
<a href="images/fireworks.jpg" title="A fireworks display" onclick="showPic(this); return false;"> Fireworks </a>
</li>
<li>
<a href="images/coffee.jpg" title="A cup of black coffe" onclick="showPic(this); return false;"> Coffee </a>
</li>
<li>
<a href="images/rose.jpg" title="A red, red rose" onclick="showPic(this); return false;"> Rose </a>
</li>
<li>
<a href="images/bigben.jpg" title="The famous clock" onclick="showPic(this); return false;"> Big Ben </a>
</li>
</ul>
<div id="placeholder">
<img src="data:images/placeholder.gif" alt="my image gallery" >
</div>
<div id="description">
<p>Choose an image</p>
</div> <script type="text/javascript" src="scripts/showPic.js"></script> <script type="application/javascript">
// alert (description.childNodes.length);
// window.onload = countBodyChildren;
//var description = document.getElementById("description");
//alert (description.childNodes[2].nodeValue);
</script>
</body>
</html>

/***      showPic.js      ***/

/**
* Created by Administrator on 9/9/2015.
*/ /*
you can use this function to count how many children nodes the body element contains
*/
function countBodyChildren() {
var body_element = document.getElementsByTagName("body")[0];
alert(body_element.nodeType);
alert( body_element.childNodes.length );
} function showPic(whicPic) {
var source = whicPic.getAttribute("href");
var text = whicPic.getAttribute("title"); var placeholder = document.getElementById("placeholder");
var img = placeholder.getElementsByTagName("img")[0];
img.setAttribute("src", source); var description = document.getElementById("description");
var desc_p = description.getElementsByTagName("p")[0];
desc_p.firstChild.nodeValue = text; }

/***      layout.css      ***/

body{
font-family: "Helvetica", "Arial", serif;
color: #333;
background-color: #ccc;
margin: 1em 10%;
} h1{
color: #333;
/*background-color: #777;*/
} a{
color: #c60;
background-color: transparent;
font-weight: bold;
text-decoration: none;
} ul{
padding:;
} li{
float: left;
padding: 1em;
list-style: none;
} img {
display: block;
clear: both;
}

The structure are like the pic shows below :

 
 

A JavaScript Image Gallery的更多相关文章

  1. JavaScript资源大全中文版(Awesome最新版)

    Awesome系列的JavaScript资源整理.awesome-javascript是sorrycc发起维护的 JS 资源列表,内容包括:包管理器.加载器.测试框架.运行器.QA.MVC框架和库.模 ...

  2. Free Slideshow, Gallery And Lightboxes Scripts

    http://bootstraphelpers.codeplex.com/SourceControl/list/changesets https://github.com/gordon-matt/Bo ...

  3. 35 Gallery – Ajax Slide

    http://html5up.net/overflow (PC,Mobile,Table) http://bridge.net/ https://github.com/bridgedotnet/Bri ...

  4. 2017年最新20个轻量的 JavaScript 库和插件

    下面这个列表中的免费 JavaScript 插件都是今年发布的,没有臃肿的一体化的框架,它们提供轻量级的解决方案,帮助 Web 开发过程更容易和更快.提供的插件可以创建滑块.响应式菜单.模态窗口.相册 ...

  5. mui学习

      改变状态栏的颜色 <meta name="apple-mobile-web-app-capable" content="yes"> <me ...

  6. Github前端项目排名

      Github前端项目排名(2016-04-04) 一.前言 近几年前端技术日新月异,从 RequireJS 到 AngularJS 再到 React,似乎每天都有新的技术诞生.而大神们总能第一时间 ...

  7. 95+强悍的jQuery图形效果插件

    现在的网站越来越离不开图形,好的图像效果能让你的网站增色不少.通过JQuery图形效果插件可以很容易的给你的网站添加一些很酷的效果. 使用JQuery插件其实比想象的要容易很多,效果也超乎想象.在本文 ...

  8. Javascript图片预加载详解

    预加载图片是提高用户体验的一个很好方法.图片预先加载到浏览器中,访问者便可顺利地在你的网站上冲浪,并享受到极快的加载速度.这对图片画廊及图片占据很大比例的网站来说十分有利,它保证了图片快速.无缝地发布 ...

  9. 利用CSS、JavaScript及Ajax实现图片预加载的三大方法

    预加载图片是提高用户体验的一个很好方法.图片预先加载到浏览器中,访问者便可顺利地在你的网站上冲浪,并享受到极快的加载速度.这对图片画廊及图片占据很大比例的网站来说十分有利,它保证了图片快速.无缝地发布 ...

随机推荐

  1. python中*args, **kwargs理解

    先来看个例子: def foo(*args, **kwargs): print 'args = ', args print 'kwargs = ', kwargs print '----------- ...

  2. JavaSE_4_集合

    1.Map和ConcurrentHashMap的区别? Map和ConcurrentHashMap的区别,Map是接口,ConcurrentHashMap是实现类 2.hashMap内部具体如何实现的 ...

  3. Spring Cloud 服务发现和消费

    服务的发现和消费 有了服务中心和服务提供者,下面我们来实现一个服务的消费者: 服务消费者主要完成两个任务——服务的发现和服务的消费,服务发现的任务是由Eureka客户端完成,而服务消费的任务是由Rib ...

  4. Node.js连接MongoDB

    使用monk访问mongodb mongodb.monk都安装了依赖的前提下: 首先启动MongoDB 服务:mongod: 进入了mongodb后台管理,再通过终端创建数据库:use monk-ap ...

  5. Spring mvc + maven + tomcat配置问题

    在用maven搭建spring mvc时候, 个人遇到过很多的问题, 现在把遇到的问题总结下: 1.  首先点击项目->Run As->Maven clean, 这一步把之前不管有没有ma ...

  6. Spring MVC中注解的简介

    参考网址:  https://blog.csdn.net/a67474506/article/details/46361195 @RequestMapping映射请求 SpringMVC 使用 @Re ...

  7. zabbix 监控项

    监控项 概述 监控项是从主机收集的数据信息. 配置主机后,你需要添加一些监控项以开始获取实际数据. 一个监控项是一个独立的指标.快速添加多个监控项的一种方法是将一个预定义的模板附加到主机.然而,为了优 ...

  8. hihoCoder #1044 : 状态压缩·一 (清垃圾)

    题意: 某车厢有一列座位,共有n个位置,清洁工要在这n个位置上清垃圾,但是不能全部位置都清理,只能选择部分.选择的规则是,连续的m个位置内,不能够清理超过q个,也就是说从第1~m个位置最多可以清q个, ...

  9. 利用ajax实现分页效果

    在网页中看到的分页效果,想一下就点击分页中的内容的时候,然后调用ajax调出对应的数据,正确的显示在相应的标签内. 1.用html实现正确的样式和结构 2.采用jquery中的ajax调出数据. 需要 ...

  10. IOS AppDelegate常用方法

    // 当应用程序启动完毕的时候就会调用(系统自动调用) - (BOOL)application:(UIApplication *)application didFinishLaunchingWithO ...