startsWith method not supported in IE any replacement for this?
本问题已经有最佳答案,请猛点这里访问。
| 1 2 | var s ="Main String"; s.startsWith("Main"); | 
将StartWith替换为类似的逻辑或所有浏览器通用的任何其他方法。
使用
这应该有效,所以继续尝试吧。
在字符串中添加原型方法:
| 1 2 3 4 5 6 7 | String.prototype.myStartsWith = function(str){ if(this.indexOf(str)===0){ return true; }else{ return false; } }; | 
现在打电话:
| 1 | s.myStartsWith("Main"); | 
号