<script type="text/javascript">
function strSub(strValue,searchStr){
//构造函数
this.strValue = strValue;
this.searchStr = searchStr;
this.strCount = 0;
if(typeof strSub.prototype.run != "function"){
strSub.prototype.run = function(){
//原型
while (this.strValue.indexOf(this.searchStr) != -1)
{
this.strValue = this.strValue.substring(this.strValue.indexOf(this.searchStr) + 1);
this.strCount++;
};
return this.strCount;
};
};
};
var ostrSub = new strSub("wwfw","wwf");
//实例化
var ostrSub1 = new strSub("lgjasdlkgjsa
klh5hhkljsk
ljsalglkahhdfsdafsfhhh","h"); //实例化
alert(ostrSub.run());
alert(ostrSub1.run());
</script>