Skip to content

Commit 7a19d2f

Browse files
committed
tijiao
1 parent 8117529 commit 7a19d2f

2 files changed

Lines changed: 77 additions & 5 deletions

File tree

‎app/images1.html‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
<script type="text/javascript" src="../js/images1.js" ></script>
88
</head>
99
<body>
10+
<a href="http://www.baidu.com" class="popup">点击打开百度</a>
1011
<h1>Snapshots</h1>
11-
<ul>
12+
<ul id="imagegallery">
1213
<li>
1314
<a href="../images/Koala.jpg" title="a koala inside">Koala</a>
1415
</li>

‎js/images1.js‎

Lines changed: 75 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33
*/
44
// 显示图片
55
function showPic(whichpic){
6+
if(!document.getElementById("placeholder")) return false;
67
var source = whichpic.getAttribute("href");
78
var placeholder = document.getElementById("placeholder");
8-
var description = document.getElementById("description");
9-
var text = whichpic.getAttribute("title");
10-
119
placeholder.setAttribute("src",source);
12-
description.firstChild.nodeValue = text;
1310

11+
if(document.getElementById("description")){
12+
var description = document.getElementById("description");
13+
var text = whichpic.getAttribute("title");
14+
description.firstChild.nodeValue = text;
15+
}
16+
return true;
1417
}
1518
//计算body子元素数量
1619
function countBodyChildren(){
@@ -22,4 +25,72 @@ function countBodyChildren(){
2225
function popUp(winURL){
2326
window.open(winURL,"popup","width=320,height=480");
2427
}
28+
29+
//点击元素弹出窗口,将事件移出行内
30+
function prepareLinks(){
31+
if(!document.getElementsByTagName) return false;
32+
var links = document.getElementsByTagName("a");
33+
for(var i=0;i<links.length;i++){
34+
if(links[i].getAttribute("class") == 'popup'){
35+
links[i].onclick = function(){
36+
popUp(this.getAttribute("href"));
37+
return false;
38+
}
39+
}
40+
}
41+
}
42+
43+
//初始检测
44+
function prepareGallery(){
45+
if(!document.getElementsByTagName) return false;
46+
if(!document.getElementById) return false;
47+
if(!document.getElementById("imagegallery")) return false;
48+
49+
var gallery = document.getElementById("imagegallery");
50+
var links = gallery.getElementsByTagName("a");
51+
52+
for(i = 0;i<links.length;i++){
53+
links[i].onclick = function(){
54+
return !showPic(this);
55+
}
56+
}
57+
}
58+
//将函数添加到windowonload的方法
59+
function addLoadEvent(func){
60+
var oldonload = window.onload;
61+
if(typeof window.onload != 'function'){
62+
window.onload = func;
63+
}else{
64+
window.onload = function(){
65+
oldonload();
66+
func();
67+
}
68+
}
69+
}
70+
71+
addLoadEvent(prepareGallery);
72+
73+
74+
75+
76+
77+
78+
79+
80+
81+
82+
83+
84+
85+
86+
87+
88+
89+
90+
91+
92+
93+
94+
95+
2596

0 commit comments

Comments
 (0)