Repository navigation
Expand file tree
/
Copy pathimages1.js
More file actions
96 lines (64 loc) · 1.99 KB
/
Copy pathimages1.js
File metadata and controls
96 lines (64 loc) · 1.99 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* Created by M.Jin on 14-7-1.
*/
// 显示图片
function showPic(whichpic){
if(!document.getElementById("placeholder")) return false;
var source = whichpic.getAttribute("href");
var placeholder = document.getElementById("placeholder");
placeholder.setAttribute("src",source);
if(document.getElementById("description")){
var description = document.getElementById("description");
var text = whichpic.getAttribute("title");
description.firstChild.nodeValue = text;
}
return true;
}
//计算body子元素数量
function countBodyChildren(){
var body_element = document.getElementsByTagName("body")[0];
alert(body_element.childNodes.length);
}
//open 方法封装得方法
function popUp(winURL){
window.open(winURL,"popup","width=320,height=480");
}
//点击元素弹出窗口,将事件移出行内
function prepareLinks(){
if(!document.getElementsByTagName) return false;
var links = document.getElementsByTagName("a");
for(var i=0;i<links.length;i++){
if(links[i].getAttribute("class") == 'popup'){
links[i].onclick = function(){
popUp(this.getAttribute("href"));
return false;
}
}
}
}
//初始检测
function prepareGallery(){
if(!document.getElementsByTagName) return false;
if(!document.getElementById) return false;
if(!document.getElementById("imagegallery")) return false;
var gallery = document.getElementById("imagegallery");
var links = gallery.getElementsByTagName("a");
for(i = 0;i<links.length;i++){
links[i].onclick = function(){
return !showPic(this);
}
}
}
//将函数添加到windowonload的方法
function addLoadEvent(func){
var oldonload = window.onload;
if(typeof window.onload != 'function'){
window.onload = func;
}else{
window.onload = function(){
oldonload();
func();
}
}
}
addLoadEvent(prepareGallery);