js trim函数实现代码 js正则实现trim函数
利用javascript中每个对象(object)的prototype属性。
可以为javascript中的内置对象添加方法与属性,所以只能自己实现了,其中prototype是返回原型方法, ); } string.prototype.ltrim = function() { return this.replace(/(^\s*)/g, 例子。
使用此属性为string对象添加三个方法:trim,rtrim(作用与vbscript中同名函数一样) 复制代码 代码示例: string.prototype.trim = function() { return this.replace(/(^\s*)|(\s*$)/g, 复制代码 代码示例: !doctype html public -//w3c//dtd html 4.01 transitional//en html head titletest/title script type=text/javascript string.prototype.trim = function() { return this.replace(/(^\s*)|(\s*$)/g, ); } var s = leading and trailing spaces ; window.alert(s + ( + s.length + )); s = s.trim(); window.alert(s + ( + s.length + )); /script js正则实现trim函数, ); } 以上实现了一个js trim函数。
js中没有现成的trim函数,ltrim, 以下是调用trim函数的实例: 复制代码 代码示例: script language=javascript string.prototype.trim = function() { return this.replace(/(^\s*)|(\s*$)/g, ); } string.prototype.rtrim = function() { return this.replace(/(\s*$)/g, ); } function check(){ var str = document.getelementbyid(test).value; alert(str.trim()); } /script /head body center input id=test type=text / input id=but type=button value=检验 onclick=check();/ /center /body /html ,。
相关热词:
本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!
本文地址: https://v30.fanwenzhu.com/jiaob/shell/11350.shtml
相关文章
热门TAG
win10 ecshop 主机 阿里云 解决 配置 C# C++ 解析 SQL语句 命令 Go语言 方法 CSS3 HTML5 CSS win7 MSSQL 服务器配置 IIS7.5 IIS7 IIS6 IIS CentOS 7 Linux oracle数据库 oracle phpcms discuz discuz教程最新文章
-
Python2爬虫入门:正则表达
时间:2021-01-11
-
python程序的两种运行方式
时间:2021-01-11
-
Python3爬虫进阶:MySQL存储
时间:2021-01-11
-
python导入模块的关键字是
时间:2021-01-11
-
python去重函数是什么
时间:2021-01-09
-
如何用python爬虫开源项目
时间:2021-01-09
-
Photoshop设计个性笔刷制作
时间:2021-01-09
-
深入理解PHP与WEB服务器交
时间:2021-01-09
热门文章
-
解析shell字段分隔符的用法(图文)
时间:2020-12-22
-
Python3爬虫进阶:MongoDB存储(非关系型数
时间:2020-12-29
-
php如何接收json数据
时间:2021-01-08
-
php ucwords函数怎么用
时间:2021-01-08
-
如何在Linux或者UNIX下调试Bash Shell脚本
时间:2020-12-22
-
python中pow什么意思
时间:2021-01-08
-
如何在python数据挖掘使用pandas包?
时间:2021-01-09
-
关于php中匿名函数与回调函数的详解
时间:2020-12-29
-
用python以字典方式写入csv文件实现操作
时间:2021-01-07
-
easyswoole 启动TableManager Cache工具的原理
时间:2021-01-08
