Latest web development tutorials

jQuery.trim () method

jQuery Misc Methods jQuery Misc Methods

Examples

Remove the spaces beginning and end of a string

$ (Function () { var str = "lots of spaces before and after"; $ ( "#original" ). Html ( "Original String: '" + str + "'" ); $ ( "#trimmed" ). Html ( "$ .trim () 'Ed: '". + $ Trim (str) + " '" );})

try it"

Definition and Usage

$ .trim () Function is used to remove both ends of the string of whitespace.

Note: $ .trim () function will remove the string at the beginning and end of all line breaks, spaces (including continuous spaces) and tabs. If these whitespace characters in the middle of the string, they will be retained and will not be removed.


grammar

$.trim( str )

参数 描述
str String类型 需要去除两端空白字符的字符串。


jQuery Misc Methods jQuery Misc Methods