Products
GG网络技术分享 2025-03-18 16:17 0
在前端开发中,经常遇到需要去掉字符串中的空格的需求。这时候,我们可以使用jQuery来轻松地完成这一任务。
// 去除字符串前后的空格,如 \" abc \" =>\"abc\"
var str = \" abc \";
var newStr = $.trim(str);
// 去除字符串中所有的空格,如 \"a b c\" =>\"abc\"
var str = \"a b c\";
var newStr = str.replace(/\\s+/g, \"\");Demand feedback