ZhipSoft.com
    冬去春来
        郑重声明:本Blog纯属个人学习、工作需要,记录相关资料。请不要发表任何有人身攻击的言论,谢谢!!www.ZhipSoft.com
posts - 94,comments - 149,trackbacks - 0

<input name="searchContent" id="searchContent" type="text" onclick="test();">
<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>



        本Blog纯属个人学习、工作需要,记录相关资料。请不要发表任何有人身攻击的言论,谢谢! www.zhipsoft.cn
posted on 2008-07-07 02:31 ZhipSoft 阅读(7723) 评论(5)  编辑  收藏 所属分类: JavaScript

FeedBack:
# re: 对js中startWith和endWith的扩展
# re: 对js中startWith和endWith的扩展
2009-02-17 15:37 | tsuihwau
这个好啊。  回复  更多评论
  
# re: 对js中startWith和endWith的扩展
2009-12-30 09:37 | 2033
不攻击不行啊.
startsWith 不是startWith
误人子弟啊  回复  更多评论
  
# re: 对js中startWith和endWith的扩展
2010-03-23 22:35 | Lean
@2033
明明可以啊
不去实践没有发言权~~
  回复  更多评论
  
# re: 对js中startWith和endWith的扩展[未登录]
2010-06-23 10:49 | fly
在IE6中无效。。。  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: