整理书籍内容(QQ:283125476 发布者:M 【重在分享,有建议请联系-》QQ号】)

养成良好的编程习惯

##如何避免团队JS冲突
* 避免实用全局变量【可使用匿名函数进行处理】以避免全局变量引起的冲突;
* 给程序一个统一的接口;

可复用性

  • 将id转换为class
  • 给元素添加跟节点挂钩 J_tab

<a >my blog</a>

var node = document.getElementById("a");     alert(node.blogName); 
 IE : 阿当的博客
 Firefox : undefined  
 alert(node.blogType); 
 IE : 前端开发
 Firefox : undefined 
 alert(node.getAttribute("blogName")); 
 IE 和Firefox : 阿当的博客
 alert(node.getAttribute("blogType")); 
 IE 和Firefox : 前端开发
<a {name:'阿当的博客',type:'前端开
发'}">my blog</a> 
<script type="text/JavaScript"> 
 var node = document.getElementById("a"); 
 var info = node.getAttribute("blogInfo"); 
 alert(typeof info);   // string 
alert(info.name);   // undefined 
alert(info.type);   // undefined 
 info = eval("("+info+")"); 
 alert(typeof info);   // object 
alert(info.name);   // 阿当的博客
alert(info.type);   // 前端开发
</script> 

相关文章:

  • 2021-08-15
  • 2021-06-08
  • 2021-11-11
  • 2022-12-23
  • 2021-11-29
  • 2021-06-19
  • 2021-06-14
  • 2022-12-23
猜你喜欢
  • 2022-02-09
  • 2021-12-03
  • 2021-05-19
  • 2021-05-30
  • 2021-06-04
  • 2022-01-08
  • 2022-12-23
相关资源
相似解决方案