小编Bhu*_*ere的帖子

代码未在IE 11中运行,在Chrome中运行良好

以下代码可以在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)

html javascript

149
推荐指数
4
解决办法
9万
查看次数

标签 统计

html ×1

javascript ×1