How to remove trailing spaces in JavaScript

藏色散人
Release: 2023-02-17 15:16:36
Original
3045 people have browsed it

How to remove trailing spaces in JavaScript: 1. Use the "osfipin.replace(/(^\s*)|(\s*$)/g, "");" method to remove leading and trailing spaces; 2. Use the "osfipin.replace(/(\s*$)/g, "");" method to remove the right space.

How to remove trailing spaces in JavaScript

The operating environment of this article: windows7 system, javascript version 1.8.5, DELL G3 computer

How to remove trailing spaces in JavaScript?

JS simple method to remove leading and trailing spaces (native regular jquery)

var osfipin= ' http://www.xxx.com/osfipin/ '; //去除首尾空格 osfipin.replace(/(^\s*)|(\s*$)/g, ""); //去除左边空格 osfipin.replace(/(^\s*)/g, ""); //去除右边空格 osfipin.replace(/(\s*$)/g, ""); //jquery 需提前引用jquery $.trim(osfipin); //另一种写法 jQuery.trim(osfipin);
Copy after login

Related introduction:

JavaScript (referred to as "JS") is a light-weighted JavaScript with function priority. magnitude, interpreted or just-in-time compiled programming language. Although it is famous as a scripting language for developing Web pages, it is also used in many non-browser environments. JavaScript is based on prototype programming, a multi-paradigm dynamic scripting language, and supports object-oriented, imperative, declarative, and functional programming paradigm.

JavaScript was first designed and implemented on the Netscape Navigator browser in 1995 by Brendan Eich of Netscape. Because Netscape was working with Sun, Netscape management wanted it to look like Java, hence the name JavaScript. But in fact its grammatical style is closer to Self and Scheme.

The standard for JavaScript is ECMAScript. As of 2012, all browsers fully support ECMAScript 5.1, and older browsers support at least the ECMAScript 3 standard. On June 17, 2015, ECMA International released the sixth edition of ECMAScript, which is officially called ECMAScript 2015, but is often called ECMAScript 6 or ES2015.

Recommended study: "javascript basic tutorial"

The above is the detailed content of How to remove trailing spaces in JavaScript. For more information, please follow other related articles on the PHP Chinese website!

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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!