33 */
44// 显示图片
55function 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子元素数量
1619function countBodyChildren ( ) {
@@ -22,4 +25,72 @@ function countBodyChildren(){
2225function 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