1、去除首尾空格:

 var txt = $('#Txt').val().trim();      

txt = txt.replace(/(^\s*)|(\s*$)/g, "");

2、去除所有空格:

 txt = txt.replace("//s/g", "");

 

posted on 2017-11-16 17:27  xs~ing  阅读(9736)  评论(0编辑  收藏  举报