去除空格、空白字符 js

 

.trim().replace(/\s/g,"")

.trim():去除首尾的空白字符

.replace(/\s/g,""):去除中间的空白字符(其中/与/g是用来包含前面的,\s 则是匹配任何空白字符,包括空格、制表符、换页符等等)

 

JavaScript:

document.getElementById('tid').innerHTML.trim().replace(/\s/g,"");

jquery:

$("#tid").val().trim().replace(/\s/g,"");

 

 

参考:https://blog.csdn.net/zhuchenglin830/article/details/82227858?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase

posted @ 2020-05-29 14:47  夏目-D  阅读(383)  评论(0编辑  收藏  举报