日期:2014-05-16 浏览次数:20389 次
对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>