Trim to remove white space

家住魔仙堡 提交于 2019-11-29 22:38:56

jQuery.trim() capital Q?

or $.trim()

No need for jQuery

JavaScript does have a native .trim() method.

var name = "    John Smith  ";
name = name.trim();

console.log(name); // "John Smith"

Example Here

String.prototype.trim()

The trim() method removes whitespace from both ends of a string. Whitespace in this context is all the whitespace characters (space, tab, no-break space, etc.) and all the line terminator characters (LF, CR, etc.).

or just use $.trim(str)

Why not try this?

html:

<p>
  a b c
</p>

js:

$("p").text().trim();
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!