zoukankan      html  css  js  c++  java
  • 高品质的JavaScript

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

    养成良好的编程习惯

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

    可复用性

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

    <a id="a" href="http://www.adanghome.com" blogName="阿当的博客" blogType="前端开发">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 id="a" href="http://www.adanghome.com" blogInfo="{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> 
    
    通过分享,结交好友~ 如本文对您有益,请给予关注。转载请注明出处!-- 小数
  • 相关阅读:
    deleted
    deleted
    HDU
    FZU 1901 Period II(KMP中的next)题解
    HDU 3374 String Problem(最大最小表示+KMP)题解
    HDU 4300 Clairewd’s message(扩展KMP)题解
    POJ 2923 Relocation(状压DP+01背包)题解
    HDU 4272 LianLianKan (状压DP+DFS)题解
    POJ 1185 炮兵阵地(状压DP)题解
    POJ
  • 原文地址:https://www.cnblogs.com/mcat/p/4506432.html
Copyright © 2011-2022 走看看