Home > Web Front-end > JS Tutorial > Introduction to the use of jquery $.trim() method_jquery

Introduction to the use of jquery $.trim() method_jquery

WBOY
Release: 2016-05-16 16:47:38
Original
1437 people have browsed it

$.trim(str)

Returns: string;

Description: Remove leading and trailing spaces from the string.

Example:

Look at the error code first. Error code:

Copy code The code is as follows :



var content = $('#content') .val();
if(content.trim() == '')
alert('empty');

The above writing method will not report an error under firefox, but It will indeed report an error

under IE, so it should be written in the following format:
Copy the code The code is as follows:



var content = $('#results').val() ;
if($.trim(content) == '')
alert('empty');

or
Copy code The code is as follows:

var content = $('#content').val();
if(jQuery.trim(content ) == '')
alert('empty');
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template