jquery $.trim () How to remove string spaces "figure example" _jquery

Source: Internet
Author: User

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.

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.