`
chengnuoangel
  • 浏览: 69910 次
  • 性别: Icon_minigender_1
  • 来自: 河南郑州
社区版块
存档分类
最新评论

对js中startWith和endWith的扩展

阅读更多

<script language="JavaScript">
 function closeUl(code){
  alert(code);
  var list = document.getElementsByTagName("li");
  for(var i=0;i<list.length;i++){
   var curLi = list[i].id;
   if(curLi.indexOf(code) != -1 && curLi.length != code.length && curLi.startWith(code)){
    alert(curLi);
    if(document.getElementById(curLi).style.display == "none"){
     if(curLi.length == code.length+5){
      document.getElementById(curLi).style.display = "block";
     }
    }else{
     document.getElementById(curLi).style.display = "none";
    }
   }
  }
 }
 
 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>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics