Home > Web Front-end > JS Tutorial > body text

javascript去掉前后空格的实例_javascript技巧

WBOY
Release: 2016-05-16 17:16:53
Original
885 people have browsed it

代码
复制代码 代码如下:

function String.prototype.Trim() { return this.replace(/(^/s*)|(/s*$)/g, ""); }   // 去掉左右空格
function String.prototype.Ltrim() { return this.replace(/(^/s*)/g, ""); }            // 去掉左空格
function String.prototype.Rtrim() { return this.replace(/(/s*$)/g, ""); }            // 去掉右空格
 


复制代码 代码如下:


 

去除所有空格
复制代码 代码如下:



下面来我们来看看Js脚本中"/s表示什么"
s 匹配任何空白字符,包括空格、制表符、换页符等等。等价于 [ fnrtv]。
 请紧记是小写的s
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!