柚子快报邀请码778899分享:js中对String去空格
body {
margin: 0;
padding: 0;
}
$(function() {
var myAction = {};
$.extend(myAction, {
test: function() {
var str = ' x u tong bao ';
var temp = str.replace(/\s+/g, ''); //去除所有空格
console.log(':' + temp + '.');
var temp = str.replace(/^\s+|\s+$/g, ''); //去除两头空格
console.log(':' + temp + '.');
var temp = str.replace(/^\s+/, ''); //去除左空格
console.log(':' + temp + '.');
var temp = str.replace(/(\s+$)/g, ''); //去除右空格
console.log(':' + temp + '.');
var temp = $.trim(str); //使用jQuery 去除两头空格
console.log(':' + temp + '.');
}
});
var init = function() {
myAction.test();
}();
})
柚子快报邀请码778899分享:js中对String去空格
精彩链接
发表评论