JavaScript工具代码

  1. html编码
    function htmlEscape(sHtml){
      return sHtml && sHtml.replace(/[<>&"]/g, function (c) { return { '<': '&lt;', '>': '&gt;', '&': '&amp;', '"': '&quot;' }[c]; });
    }
  2. 写console.log
    function debugLog() {
        window.console && window.console.log && window.console.log.apply(window.console, arguments);
    }
  3. js判断是否数组
    function isArray(val){
      return toString.apply(val) === '[object Array]';
    }
  4. js移除数组指定元素
    var index = arr.indexOf(values[i]);
    if (index > -1) {
      arr.splice(index, 1);
    }
  5. js数组函数(英语不好,经常记混)

    shift:从集合中把第一个元素删除,并返回这个元素的值。
    unshift: 在集合开头添加一个或更多元素,并返回新的长度。
    push:在集合中添加元素,并返回新的长度。
    pop:从集合中把最后一个元素删除,并返回这个元素的值。

  6. js无刷新文件上传
    https://github.com/blueimp/jQuery-File-Upload/wiki/Basic-plugin
原文地址:https://www.cnblogs.com/liqipeng/p/6102201.html