在和網友的程式交流中,又再次因為好奇心的推使我又去找相關的資料,本來不知道該由何去搜尋,不過最後在夢遊的狀態下,醒起了原來 scriptaculous 有類似的寫法,經過了一個小時再加上半個小時的研究和分析和最重要的抽取代碼過程後,就出現了以下的簡化版本 = = , 希望有需要的你慢慢品嚐我為你準備的大餐..但切記不要罵我這個小小的廚子了 = = .. 真的很累人的…單是一個 prototype.js 就玩了的很久…要下班了..
HTML 網頁(留意 script.js?load=abc) :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns ="http://www.w3.org/1999/xhtml" > <head > <meta http-equiv ="Content-Type" content ="text/html; charset=UTF-8" > <title > new document </title > <meta http-equiv ="Pragma" content ="no-cache" /> <meta http-equiv ="Expires" content ="-1" /> <meta http-equiv ="Cache-Control" content ="no-cache" /> <script src ="script.js?load=abc" language ="javascript" type ="text/javascript" > </script > </head > <body > This is a test page </body > </html >
Script.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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 Object .extend = function (destination, source ) { for (var property in source) { destination[property] = source[property]; } return destination; } var $break = new Object ();var $continue = new Object ();var Enumerable = { each: function (iterator ) { var index = 0 ; try { this ._each(function (value ) { try { iterator(value, index++); } catch (e) { if (e != $continue ) throw e; } }); } catch (e) { if (e != $break ) throw e; } return this ; }, findAll: function (iterator ) { var results = []; this .each(function (value, index ) { if (iterator(value, index)) results.push(value); }); return results; } } Object .extend(Enumerable, { select: Enumerable.findAll }); var $A = Array .from = function (iterable ) { if (!iterable) return []; if (iterable.toArray) { return iterable.toArray(); } else { var results = []; for (var i = 0 , length = iterable.length; i < length; i++) results.push(iterable[i]); return results; } } Object .extend(Array .prototype, Enumerable);if (!Array .prototype._reverse) Array .prototype._reverse = Array .prototype.reverse; Object .extend(Array .prototype, { _each: function (iterator ) { for (var i = 0 , length = this .length; i < length; i++) iterator(this [i]); } }); var SeekUrlAnalyze = { Version: '1.7.0' , showStr: function (stringName ) { alert(stringName); }, load: function ( ) { $A(document .getElementsByTagName("script" )).findAll( function (s ) { return (s.src && s.src.match(/script\.js(\?.*)?$/ )) } ).each( function (s ) { var path = s.src.replace(/script\.js(\?.*)?$/ ,'' ); var includes = s.src.match(/\?.*load=([a-z,]*)/ ); (includes ? includes[1 ] : '' ).split('&' ).each( function (include ) { SeekUrlAnalyze.showStr(include) } ); } );} } SeekUrlAnalyze.load();