to wssgwps(小刀会) :javascript中的字符串对象中没有这个函数,只能自己写了

解决方案 »

  1.   

    这个不行啊,是php的去空格,还有是vbscript的去空格!
      

  2.   

    to:qiushuiwuhen(秋水无恨) 
    怎么用?举个实例行吗?
      

  3.   

    str="   fdsfsd  "
    str=str.replace(/(^\s+|\s+$)/g,"")
    接过后str="fdsfsd"
      

  4.   

    str="   ex ecu te "
    str=str.replace(/ /g,"")
    结果str="execute"
      

  5.   

    1
    <script>
    function jsTrim(){
    str=strText.value
    str = str.replace(/(^\s*|\s*$)/g,"")
    strText.value=str
    }
    </script>
    <input id=strText value="     abd    "><input type=button value=去掉字符串前后空格 onclick=jsTrim()>2
    <script>
    function jsTrim(){
    str=strText.value
    window.execScript("str=Trim(str)","vbscript")
    strText.value=str
    }
    </script>
    <input id=strText value="     abd    "><input type=button value=去掉字符串前后空格 onclick=jsTrim()>
      

  6.   

    function funcDeleteSpaces(str)   
    {
    var count = 0;

    for (var i = 0; i < str.length; i++) 
    {
    if (str.charAt(i) == " ") 
    {
    count++;
    }
    else
    {
    break;
    }
    }
    str = str.substring(count, str.length);
    count = 0;

    for (var i = str.length; i >=0; i--) 
    {
    if (str.charAt(i - 1) == " ") 
    {
    count++;
    }
    else
    {
    break;
    }
    }
    str = str.substring(0, str.length - count);

    return str;
    }