- //JS去掉左边空格
- functionlTrim(str)
- {
- if((typeof(str)!="string")||!str)
- {
- return"";
- }
- returnstr.replace(/(^\s*)/g,"");
- }
- //JS去掉右边空格
- functionrTrim(str)
- {
- if((typeof(str)!="string")||!str)
- {
- return"";
- }
- returnstr.replace(/(\s*$)/g,"");
- }
- //JS去掉两边空格
- functiontrimStr(str)
- {
- if((typeof(str)!="string")||!str)
- {
- return"";
- }
- returnstr.replace(/(^\s*)|(\s*$)/g,"");
- }
JS 去空格
最新推荐文章于 2024-11-18 14:41:17 发布
本文介绍了三种JavaScript函数用于去除字符串的左右空格:lTrim、rTrim和trimStr。这些函数可以帮助开发者在处理文本数据时更高效地清理输入。
561

被折叠的 条评论
为什么被折叠?



