jquery $.trim () Remove string whitespace

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.