First of all, the original JS does not contain a trim () method. If you think so, it must be written in Java.
The workaround is as follows:
1. Use the $.trim provided by jquery ([object to manipulate]);
2. Encapsulate a method to intercept the white-space character.
In this case, the first method, the trim of jquery
The Jquery.trim () function is used to remove whitespace characters at both ends of a string. This function removes whitespace characters at the beginning and end of the string (until the first non-whitespace string is encountered). It clears common whitespace characters, including line breaks, spaces, tabs, and so on.
The function belongs to the global jquery object.
Grammar
JQuery 1.0 adds this static function.
Jquery.trim (str)
Parameters |
Description |
Str |
String types need to remove whitespace characters from both ends. |
If the parameter str is not a string type, the function will automatically convert it to a string (typically called its ToString () method). If the parameter str is null or undefined, an empty string ("") is returned.
return value
The return value of the Jquery.trim () function is of type string, which returns the string that is stripped of the empty string at both ends.
Jquery.trim () function and trim () usage