String.prototype.trim() - JavaScript | js trim
trim()方法会从一个字符串的两端删除空白字符。在这个上下文中的空白字符是所有的空白字符 (space,tab,no-breakspace等)以及所有行终止符字符(如LF,CR等)。ThesourceforthisinteractiveexampleisstoredinaGitHubrepository.Ifyoudliketocontributetotheinteractiveexamplesproject,pleaseclonehttps://github.com/mdn/interactive-examples[1]andsendusapullrequest.语法str.trim()返回值一个代表调用字符串两端去掉空白的新字符串。描述trim()方法返回一个从两头去掉空白字符的字符串,并不影响原字符串本身。例子使用 trim()下面...
trim() 方法会从一个字符串的两端删除空白字符。在这个上下文中的空白字符是所有的空白字符 (space, tab, no-break space 等) 以及所有行终止符字符(如 LF,CR等)。
The source for this interactive example is stored in a GitHub repository. If youd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples[1] and send us a pull request.
语法 str.trim() 返回值一个代表调用字符串两端去掉空白的新字符串。
描述trim() 方法返回一个从两头去掉空白字符的字符串,并不影响原字符串本身。
例子 使用 trim()下面的例子中将显示小写的字符串 foo:
var orig = foo ; console.log(orig.trim()); // foo // 另一个 .trim() 例子,只从一边删除 var orig = foo ; console.log(orig.trim()); // foo 兼容旧环境如果 trim() 不存在,可以在所有代码前执行下面代码
if (!String.prototype.trim) { String.prototype.trim = function () { return this.replace(/[suFEFFxA0]+|[suFEFFxA0]+$/g, ); }; } 规范 浏览器兼容性The compatibility table in this page is generated from structured data. If youd like to contribute to the data, please check out https://git...