Home  >  Article  >  Web Front-end  >  What symbols can be removed by the jquery trim method?

What symbols can be removed by the jquery trim method?

青灯夜游
青灯夜游Original
2021-11-15 16:58:312140browse

In jquery, the trim() method can remove whitespace symbols at both ends of a string, including newlines, spaces, and tabs. The syntax is "$.trim(string)"; the parameter "string" specifies the need A string with whitespace characters removed from both ends.

What symbols can be removed by the jquery trim method?

The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.

In jquery, the trim() method can remove whitespace characters at both ends of a string.

$.trim() function removes all newline characters, spaces (including consecutive spaces) and tab characters at the beginning and end of the string. If whitespace characters are in the middle of the string, they are retained and not removed.

Syntax:

$.trim(string)
  • string: Required parameter, String type, specifies the string that needs to remove blank characters at both ends.

Example:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <script src="js/jquery-1.10.2.min.js"></script>

</head>
<body>
	
<pre id="original">

<script>
$(function () { 
	var str = "         lots of spaces before and after         ";
	$( "#original" ).html( "原始字符串: &#39;" + str + "&#39;" );
	$( "#trimmed" ).html( "使用$.trim()&#39;后: &#39;" + $.trim(str) + "&#39;" );
})
</script>
 

The above is the detailed content of What symbols can be removed by the jquery trim method?. For more information, please follow other related articles on the PHP Chinese website!

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