js 字符串扩展
<script type="text/javascript" language="javascript"> 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,""); } </script> <script type="text/javascript" language="JavaScript"> function test() { var a = "abcdef".startWith("abc"); alert("a : " + a); var b = "abcdef".endWith("def"); alert("b : " + b); } String.prototype.endWith = function(str) { if (str == null || str == "" || this.length == 0 || str.length > this.length) return false; if (this.substring(this.length - str.length) == str) return true; else return false; return true; } String.prototype.startWith = function(str) { if (str == null || str == "" || this.length == 0 || str.length > this.length) return false; if (this.substr(0, str.length) == str) return true; else return false; return true; } </script>
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。