用prototype给JS中的String对象追加函数

来源:互联网 发布:淘宝大学官网首页 编辑:程序博客网 时间:2024/05/22 10:46

如:追加去空格函数

String.prototype.Trim =function(){ return this.replace(/(^\s*)|(\s*$)/g,"");}String.prototype.LTrim =function(){ return this.replace(/(^\s*)/g,"");}String.prototype.RTrim =function(){ return this.replace(/(\s*$)/g,"");} 

引用时语句如下

document.getElementById('space').value.Trim()


原创粉丝点击