jquery $.trim () How to remove string spaces "figure example"
Grammar
the Jquery.trim () function is used to remove white space characters at both ends of the string.
Role
This function can remove white space characters at the beginning and end of the string until the first non-white-space string is encountered. It clears common whitespace characters, including line breaks, spaces, tabs, and so on.
Parameters
if parameter str is not a string type, the function will automatically convert it to a string (generally calling 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 string, which returns a string that is stripped of the blank string at both ends.
Example & Description
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >
can't take it for granted that you want to be like Java. With a string point method.
Wrong wording:
$ ("#showBtn1"). Click (function () {
var content = $ (' #content '). Val ();
if (content.trim () = = ") {
alert (' null ');
}
});
Description: the above writing in Firefox will not be an error, in IE and Google under the correct error.
Correct wording:
$ ("#showBtn"). Click (function () {
var content = $ (' #content '). Val ();
if ($.trim (content) = = ') {
alert (' null ');
}
});
The above jquery $.trim () method of removing string spaces "Figure example" is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud-dwelling community.