发表于: 2019-04-19 20:42:19

1 705


今天完成的任务

lookdom编程思想 总结如下:

/*第五章 最佳实践 本章讲解了平稳退化 js分离 性能优化的一些简单内容!!*/
       function prepareLinks() {
           var links = document.getElementsByTagName("a");
           for (let i = 0; i < links.length; i++) {
               if (links[i].getAttribute("class") == "popup") {
                   links[i].onclick = function () {
                       popUp(this.getAttribute("href"));
                       return false;
                   }
               }

           }
       }
       function popUp(winURL) {
           window.open(winURL, "popup", "width=320,height=480");
       }
       function showPic(whichpic) {
           if (!document.getElementById("placeholder")) {
               return false;
           }
           var sourse = whichpic.getAttribute("href");
           var placeholder = document.getElementById("placeholder");
           if (placeholder.nodeName != "IMG") {
               return false;
           }
           placeholder.setAttribute("src", sourse);
           if (document.getElementById("description")) {
               var text = whichpic.getAttribute("title") ? whichpic.getAttribute("title") : "";
               var description = document.getElementById("description");
               if (description.firstChild.nodeType == 3) {
                   description.firstChild.nodeValue = text;
               }
           }
           return true;
       }
       /*第六章 案例研究:图片库改进版  本章讲解了平稳退化 js分离 性能优化的一些简单内容 相比较第五章讲解的更深层次!*/
       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 (let i = 0; i < links.length; i++) {
               links[i].onclick = function () {
                   return showPic(this) ? false : true;
               }
           }
       }
       //由Simon Willison提供的使onlond函数加载多次的函数!!
       function addLoadEvent(func) {
           var oldonload = window.onload;
           if (typeof window.onload != 'function') {
               window.onload = func;
           } else {
               window.onload = function () {
                   window.onload = function () {
                       oldonload();
                       func();
                   }
               }
           }
       }
       window.onload = prepareGallery;

       /*第七章 动态创建标记*/



返回列表 返回列表
评论

    分享到