星空网 > 软件开发 > Java

javascript dom编程艺术笔记之图片库的改进

dom的操作要遵守的原则

1.平稳退化

2.分离javascript

3.向后兼容

4.性能考虑

 

改进后的显示图片方法

 

function showpic(whichpic){  if(!document.getElementById("placeholder")) return false;  var source=whichpic.getAttribute("href");  var placeholder=document.getElementById("placeholder");  if(placeholder.nodeName!="IMG") return false;  placeholder.setAttribute("src",source);  if(document.getElementById("description")){  var text=whichpic.getAttribute("title")?whichpic.getAttribute("title"):"";  var description=document.getElementById("description");  if(description.firstChild.nodeType==3){    discription.firstChild.nodeValue=text;   }  }  return true;}

 

新添加的分离html和javascript方法

function prepareGallery(){  if(!document.getElementById) return false;  if(!document.getElementByTagName) return false;  if(!document.getElementById("imagegallery")) return false;  var gallery=document.getElementById("imagegallery");  var link=gallery.getElementByTagName("a");  for(var i=0; i<link.length ;i++){    link[i].onclick=function(){      return showpic(this) ? false:true;    }  }}

 

添加事件的方法

function addLoadEvent(func){  var oldonload=window.onload;  if(typeof window.onload!='function'){    window.onload=func;  }else{    window.onload-function(){      oldonload();      func();    }  } }




原标题:javascript dom编程艺术笔记之图片库的改进

关键词:JavaScript

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

备战策略:https://www.goluckyvip.com/tag/4793.html
英国本土海外仓:https://www.goluckyvip.com/tag/47935.html
英国仓海外仓:https://www.goluckyvip.com/tag/47936.html
英国的fba:https://www.goluckyvip.com/tag/47938.html
英国的海外仓:https://www.goluckyvip.com/tag/47939.html
站内广告预算:https://www.goluckyvip.com/tag/4794.html
怎样做出一个有利可图的SaaS产品?:https://www.kjdsnews.com/a/1836639.html
【再放信号】美国Etsy即将放开中国卖家入驻,官方邮件你收到了吗?:https://www.kjdsnews.com/a/1836640.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流