jquery $.trim () Remove string whitespace
Grammar
jQuery.trim()
function is used to remove whitespace characters at both ends of a string.
Role
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.
Parameters
If the argument str
is not a string type, the function will automatically convert it to a string (its ToString () method is generally called). If the argument str
is null or undefined, an empty string ("") is returned.
return value
jQuery.trim()
The return value of the function is of type string, which returns the string after the blank string is stripped.
Example & Description
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" > $("#showBtn"). Click (function(){ varContent = $ (' #content '). Val (); if($.trim (content) = = ") {alert (Empty); } } ); $("#showBtn1"). Click (function(){ varContent = $ (' #content '). Val (); if(Content.trim () = = ") {alert (Empty); } } ); </script> </body>Not for granted, like Java. Use a string-point method.
Error wording:
function () { var content = $ (' #content '). Val (); if (Content.trim () = = ") { alert (' empty '); } });
Description: The above wording in Firefox will not error, in IE and Google will error.
Correct wording:
function () { var content = $ (' #content '). Val (); if ($.trim (content) = = ") { alert (' empty '); } });
The information you have referenced
Reference: http://www.365mini.com/page/jquery_trim.htm
jquery $.trim () Remove string whitespace