以下代码可以在Chrome中运行而不会出现问题,但会在Internet Explorer 11中引发以下错误.
对象不支持属性或方法'startsWith'
我将元素的ID存储在变量中.有什么问题?
function changeClass(elId) {
var array = document.getElementsByTagName('td');
for (var a = 0; a < array.length; a++) {
var str = array[a].id;
if (str.startsWith('REP')) {
if (str == elId) {
array[a].style.backgroundColor = "Blue";
array[a].style.color = "white";
} else {
array[a].style.backgroundColor = "";
array[a].style.color = "";
}
} else if (str.startsWith('D')) {
if (str == elId) {
array[a].style.backgroundColor = "Blue";
array[a].style.color = "white";
} else {
array[a].style.backgroundColor = "";
array[a].style.color = "";
}
}
}
}Run Code Online (Sandbox Code Playgroud)
<table> …Run Code Online (Sandbox Code Playgroud)