Jquery.trim () function and trim () usage

Source: Internet
Author: User

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

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.