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

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

WBOY
WBOYOriginal
2016-05-16 16:47:381409browse

$.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');
Statement:
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