去除空格、空白字符 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

上一篇:论文笔记系列-Neural Architecture Search With Reinforcement Learning


下一篇:Mybatis基础知识点:trim标签的使用