zoukankan      html  css  js  c++  java
  • (转)js去空格

    <script language="javascript" type="text/javascript">
    function checkName(){
       
        String.prototype.Trim   =   function()   //给string增加个Trim()方法
    {  
    return   this.replace(/(^\s*)|(\s*$)/g,   "");  
    }  
       
    String.prototype.LTrim   =   function()    //给string增加个LTrim()方法,去左边的空格

    {  
    return   this.replace(/(^\s*)/g,   "");  
    }  
       
    String.prototype.RTrim   =   function() // 给string增加个RTrim()方法,去右边的空格

    {  
    return   this.replace(/(\s*$)/g,   "");  
    }   


    String.prototype.len = function()           // 给string增加个len ()方法,计算string的字节数
    {
        return this.replace(/[^\x00-\xff]/g, "xx").length;
    }


        var obj=document.getElementById("txtContent").value;   //取得textbox里的数据
        var count=obj.Trim().len();                                              //去点空格后计算字节数
        if(count<1||obj=="请填写评论的内容!")
        {
           document.getElementById("U_name_Err1").className="show";
            document.getElementById("U_name_Err2").className="unshow";
           return false;
        }
         if(count>1000)
        {
           document.getElementById("U_name_Err2").className="show";
           document.getElementById("U_name_Err1").className="unshow";
           return false;
        }
        else
        {
           document.getElementById("U_name_Err2").className="unshow";
           document.getElementById("U_name_Err1").className="unshow";
        }
        return true;
    }
    </script>

  • 相关阅读:
    HTTPS之acme.sh申请证书
    GoAccess日志分析工具
    KVM之CPU虚拟化
    自动化运维之PSSH
    Hadoop+HBase 集群搭建
    SSH + Google Authenticator 安全加固
    查看数据的类型(python)
    在word中,替换多个词语。正则表达式中 [] {} 是可以连用的(python)
    方差分析的前提,与检验,以及球形检验
    清屏处理(汇编)
  • 原文地址:https://www.cnblogs.com/s021368/p/1648658.html
Copyright © 2011-2022 走看看