写成类的方法格式如下:(str.trim();)
<script language="javascript">
String.prototype.trim=function(){
return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.ltrim=function(){
return this.replace(/(^\s*)/g,"");
}
String.prototype.rtrim=function(){
return this.replace(/(\s*$)/g,"");
}
</script>
写成函数可以这样:(trim(str))
<script type="text/javascript">
function trim(str){ //删除左右两端的空格
return str.replace(/(^\s*)|(\s*$)/g, "");
}
function ltrim(str){ //删除左边的空格
return str.replace(/(^\s*)/g,"");
}
function rtrim(str){ //删除右边的空格
return str.replace(/(\s*$)/g,"");
}
</script>

相关文章:

  • 2022-12-23
  • 2021-10-04
  • 2021-06-17
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-31
  • 2021-09-28
  • 2022-02-19
  • 2022-12-23
  • 2022-01-23
  • 2021-08-06
相关资源
相似解决方案