`
xitonga
  • 浏览: 587611 次
文章分类
社区版块
存档分类
最新评论

JS 去空格

 
阅读更多
  1. //JS去掉左边空格
  2. functionlTrim(str)
  3. {
  4. if((typeof(str)!="string")||!str)
  5. {
  6. return"";
  7. }
  8. returnstr.replace(/(^\s*)/g,"");
  9. }
  10. //JS去掉右边空格
  11. functionrTrim(str)
  12. {
  13. if((typeof(str)!="string")||!str)
  14. {
  15. return"";
  16. }
  17. returnstr.replace(/(\s*$)/g,"");
  18. }
  19. //JS去掉两边空格
  20. functiontrimStr(str)
  21. {
  22. if((typeof(str)!="string")||!str)
  23. {
  24. return"";
  25. }
  26. returnstr.replace(/(^\s*)|(\s*$)/g,"");
  27. }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics