我使用了Methode startsWith,它只在Android5和更高版本上工作。
if(array[var].startsWith("code"))还有另外一种简单的方法吗?这样它也能在Android 4上工作吗?
发布于 2016-03-15 08:31:13
startsWith不是cordova方法,而是javascript方法。它将削弱对webview的支持。
在这里您可以看到浏览器支持Objects/String/startsWith
请注意,它说:
在Android 5上,webview基于铬和可更新,现在它使用的是48版本,因此它支持startsWith。
在该链接中,您有一个填充,所以您可以将其用于以前的版本。
if (!String.prototype.startsWith) {
String.prototype.startsWith = function(searchString, position){
position = position || 0;
return this.substr(position, searchString.length) === searchString;
};
}https://stackoverflow.com/questions/35992020
复制相似问题