风之稍语 2006-3-4 14:42
javascript语法中有类似于trim(var)这样的方法吗
请问在javascript语法中有类似于trim(字符串)这样的方法吗,即把字符串两头的空格去掉
Nothing 2006-3-6 23:10
function trim(str)
{
return str.replace(/^s*|s*$/g,"");
}
var str = " this is a test ";
str = trim(str);
或是
var str = " this is a test ";
str = str.replace(/^s*|s*$/g,"");