JS JavaScript如何去除字符串中空白
1、直接上代码
function trim(pValue){
return pValue.replace(/^[\s]*/gi,"").replace(/[\s]*$/gi,"");
}
2、用法

3、效果

4、成功去掉两端空格
5、<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<button onclick="fun()">测试</button>
<script type="text/javascript">
function fun(){
alert(trim(' 你好我前面和后面都有空格 '))//id)
}
function trim(pValue){
return pValue.replace(/^[\s]*/gi,"").replace(/[\s]*$/gi,"");
}
</script>
</body>
</html>
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
阅读量:75
阅读量:63
阅读量:32
阅读量:119
阅读量:106