zoukankan      html  css  js  c++  java
  • JavaScript开发时的四个注意事项

    1.可点击的都应该是链接

    不要给除锚元素(<a>)以外的元素绑定click事件。这一点对于键盘用户很重要,因为他们在仅通过键盘获取元素焦点时会遇到困难。
    不过个人感觉锚元素还是应该只用作链接,而一些功能性的操作(比如Google Reader的Mark all as new),最好还是用<span>来标注,accessibility的问题可以通过快捷键等方式解决。这样做可以更好的还原HTML元素的 语义。 

    2.简单的for循环优化

    for ( var i = 0, j = elements.length; i < j; ++i )

    3.用匿名函数来作为事件处理程序 

    尤其是对于短小的函数,创建一个匿名函数会比使用一个命名函数的引用更具可读性
    anchor.onclick = function() { map.goToPosition( home ); return false; }

    4.使用Array.join代替字符串连接(concatenating strings) 

    var text = 'There are' + elements.length + 'members in the elements array.';
    var text = ['There are', elements.length, 'members in the elements array.'].join(' ');

  • 相关阅读:
    python命令行参数处理
    linux进程管理
    hadoop
    linux进程间通信之信号
    HA for openstack
    ubutun 安装php7.1x
    php 函数小技巧(一)
    git error: RPC failed; result=56, HTTP code = 200
    php面试题汇总四(基础篇附答案)
    php面试题汇总三(基础篇附答案)
  • 原文地址:https://www.cnblogs.com/BigIdiot/p/2826502.html
Copyright © 2011-2022 走看看