zoukankan      html  css  js  c++  java
  • js常用方法总结

    1.trim字符串前后空格

    function trim(str) { // trim字符串前后空格
                return str.replace(/(^s*)|(s*$)/g, '');
    }

    2.判断字符串是否为null

    function isNull(str) { // 判断字符串是否为null
                if (typeof str == 'undefined' || str === null) {
                    return true;
                } else {
                    return false;
                }
    }

    3.判断字符串是否为空

    function isBlank(str) { // 判断字符串是否为空
                if (typeof str === 'undefined' || str === null || trim(str) === '') {
                    return true;
                } else {
                    return false;
                }
    }

    4.判断字符串是否全为数字

    function(str) { // 判断字符串是否全为数据
                if (typeof str === 'undefined' || str === null || trim(str) === '') {
                    return false;
                }
                if (!(/^d*$/g).test(str)) {
                    return false;
                }
                return true;
    }

    未完待续

  • 相关阅读:
    link和@import区别
    常用的正则表达式
    virtual dom
    git常用命令
    系统管理与进程命令
    Shell 命令
    软件安装命令
    vim 详解
    网络命令
    帮助与用户管理命令
  • 原文地址:https://www.cnblogs.com/Jason-Xiang/p/7133684.html
Copyright © 2011-2022 走看看