Home > Article > Web Front-end > What symbols can be removed by the jquery trim method?
In jquery, the trim() method can remove whitespace symbols at both ends of a string, including newlines, spaces, and tabs. The syntax is "$.trim(string)"; the parameter "string" specifies the need A string with whitespace characters removed from both ends.
The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.
In jquery, the trim() method can remove whitespace characters at both ends of a string.
$.trim() function removes all newline characters, spaces (including consecutive spaces) and tab characters at the beginning and end of the string. If whitespace characters are in the middle of the string, they are retained and not removed.
Syntax:
$.trim(string)
string: Required parameter, String type, specifies the string that needs to remove blank characters at both ends.
Example:
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <script src="js/jquery-1.10.2.min.js"></script> </head> <body> <pre id="original"><script> $(function () { var str = " lots of spaces before and after "; $( "#original" ).html( "原始字符串: '" + str + "'" ); $( "#trimmed" ).html( "使用$.trim()'后: '" + $.trim(str) + "'" ); }) </script>
The above is the detailed content of What symbols can be removed by the jquery trim method?. For more information, please follow other related articles on the PHP Chinese website!