JS trim()方法使用

mac2022-06-30  89

trim去掉了字符串两端Unicode编码小于等于32(\u0020)的所有字符。(参考https://blog.csdn.net/leeqihe/article/details/81006611)

JS trim()方法使用上有浏览器限制:

1.直接使用

string.trim()

 浏览器版本限制:JavaScript Version 1.8

2.间接使用<即自己使用正则构造类trim的方法>

function myTrim(x) { return x.replace(/^\s+|\s+$/gm,''); } function myFunction() { var str = myTrim(" Hello World! "); alert(str); }

  

  

转载于:https://www.cnblogs.com/yanghao2019/p/11049446.html

相关资源:JavaScript如何自定义trim方法
最新回复(0)