博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
显示缩略列表 JS DOM
阅读量:7300 次
发布时间:2019-06-30

本文共 2614 字,大约阅读时间需要 8 分钟。

以下body部分:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<!DOCTYPE html>
<
html 
lang
=
"en"
>
<
head
>
<
meta 
charset
=
"utf-8"
>
<
title
>Explaining the Ddocument Ob Model</
title
>
 
<
link 
href
=
"style08.css" 
type
=
"text/css" 
rel
=
"stylesheet" 
/>
</
head
>
<
body
>
<
h1
> What is the Document object Model?</
h1
>
<
p
>
The <
abbr 
title
=
"Worle Wide Web Consortium"
>W3C</
abbr
> defines the <
abbr 
title
=
"Object Model"
>DOM</
abbr
> as:
</
p
>
<
blockquote 
cite
=
"http://www.w3.org/DOM/"
>
<
P
>
A platform- and language-neutral interface that will allow programs 
and scripts to dynamically access and update the content,structure and styles of documents.
</
p
>
</
blockquote
>
<
p
>
It is an <
abbr 
title
=
"Application Programming Interface"
>API</
abbr
>
that can be used to navigate <
abbr 
title
=
"eXtensible Markup Language"
>XML</
abbr
>
documents.
</
p
>
<
script 
src
=
"test.js"
></
script
</
body
>
</
html
>

以下是js部分:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
function 
addLoadEvent(func){    
//不管在页面加载完毕执行多少个函数,都应付自如
var 
oldonload = window.onload;
if
(
typeof 
window.onload != 
'function'
){
window.onload = func;
}
else
{
window.onload = 
function
(){
oldonload();
func();
}
}
}
 
function 
displayAbbreviations(){
//检查兼容性
if
(!document.getElementsByTagName||!document.createElement||!document.createTextNode) 
return 
false
;
 
var 
abbreviations = document.getElementsByTagName(
"abbr"
);     
//取得所有缩略词
if
(abbreviations.length < 1) 
return 
false
;
var 
defs = 
new 
Array();
for
(
var 
i=0; i < abbreviations.length; i++){                  
//遍历这些缩略词
var 
current_abbr = abbreviations[i];
var 
definition = current_abbr.getAttribute(
"title"
);
var 
key = current_abbr.lastChild.nodeValue;
defs[key] = definition;
}
var 
dlist = document.createElement(
"dl"
);                   
//创建定义列表  
for
( key 
in 
defs){                                          
//遍历定义
var 
definition = defs[key]; 
var 
dtitle = document.createElement(
"dt"
);                  
//创建定义标题
var 
dtitle_text = document.createTextNode(key);
dtitle.appendChild(dtitle_text);
var 
ddesc = document.createElement(
"dd"
);                    
//创建定义描述
var 
ddesc_text = document.createTextNode(definition);
ddesc.appendChild(ddesc_text);                               
//把它们添加到定义列表
dlist.appendChild(dtitle);
dlist.appendChild(ddesc);
}
 
var 
header = document.createElement(
"h2"
);                   
//创建标题
var 
header_text = document.createTextNode(
"Abbreviations"
);
header.appendChild(header_text);
document.body.appendChild(header);                           
//把标题添加到页面主体
document.body.appendChild(dlist);                            
//把定义列表添加到主体
 
}
 
 
addLoadEvent(displayAbbreviations);

页面预览效果:

本文转自  小旭依然  51CTO博客,原文链接:http://blog.51cto.com/xuyran/1783576

转载地址:http://vybnm.baihongyu.com/

你可能感兴趣的文章
MySql-5.1.32的data文件夹找不到是什么原因呢?
查看>>
Func与Action, delegate, event, var, dynamic, 匿名方法,lambda, 大量的关键都使用相同功能,大大增加C#复杂性...
查看>>
欣赏一下OFFICE 2013 PLUS吧
查看>>
结束贪心hdu 2491 Priest John's Busiest Day
查看>>
如何将sql 执行的错误消息 记录到本地文件中
查看>>
简单的ant打包,修改渠道号
查看>>
打开关闭输入输出音频设备
查看>>
定义提示【Cocos2D-X 游戏引擎】常见错误备忘
查看>>
(原创)C++半同步半异步线程池
查看>>
poj2405
查看>>
OC类属性
查看>>
Android_4.0_新特性
查看>>
Oracle中exp,imp的使用详解
查看>>
OSX: 10.9 Mavericks的重要更新技术细节(1)
查看>>
重命名数据库存储过程/函数/视图/触发器应注意的问题
查看>>
UBUNTU下如何开启SSHD服务
查看>>
jsp动作之 setProperty
查看>>
一步步实现看图工具(四)
查看>>
ios 6 横竖屏转换
查看>>
算法--逆波兰表达式(数学逆波兰表达式和交并集逆波兰表达式)
查看>>