您的位置:首页 > Web前端 > JavaScript

《JavaScript DOM编程艺术》笔记1

2016-03-08 11:34 435 查看
1:DOM的学习

一份文档就是一棵节点树;

节点分为不同的类型:元素节点,属性节点,文本节点;

getElementById返回的是一个对象;

getElementByTagName和getElementByclassName返回的是一个对象数组,分别对应着文档中一个特定的元素节点;

每个节点都是一个对象;

getAttribute获取属性节点的值

setAttribute设置属性节点的值

例子:`这里写代码片

“http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd”>

Image Gallery

Snapshots

Fireworks

Coffee

Rose

Big Ben



Choose an image.

function showPic(whichpic) {
var source = whichpic.getAttribute("href");
var placeholder = document.getElementById("placeholder");
placeholder.setAttribute("src",source);
var text = whichpic.getAttribute("title");
var description = document.getElementById("description");
description.firstChild.nodeValue = text;
}

`
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: