我正在尝试根据所选产品对我的产品详细信息对象进行分类。
if (prodCode.startsWith("1") || prodCode.startsWith("4")) {
ProductDetails = obj.MachineDetails;
}
else if (prodCode.startsWith("6")) {
if (prodCode.charAt(3) == '3' || prodCode.charAt(3) == '4') {
ProductDetails = obj.BoxDetails;
}
else {
ProductDetails = obj.SomeDetails;
}
}
else if (prodCode.startsWith("2") || prodCode.startsWith("3")) {
ProductDetails = obj.SomeOtherDetails;
}
它在 Android 4.4 以上工作正常,但在 android 4.4 中出现错误:
Object 1011 has no method 'startsWith'
1011
是我的产品代码。
有人知道为什么会发生这种情况吗?
最佳答案
在 Android 版本之间,JavaScript 引擎并不总是相同,并且最新功能并不总是可用。
我遇到了同样的问题:你必须在调用startsWith之前添加一个polyfill。
检查 Mozilla 页面上的 polyfill 部分:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith
关于javascript - 对象 1011 没有方法 'startsWith',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46682698/