<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head>
<body>
<input name="searchContent" title="改变值后,单击这里" id="searchContent" type="text" value="abcdef" οnclick="test(this.value);">
<SCRIPT type="text/javascript" language="JavaScript">
function test(value){
var a = value.startWith("abc");
alert("a : "+a);
var b = value.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>
</body>
</html>
js中startWith和endWith的扩展
最新推荐文章于 2022-11-24 18:28:44 发布