首页 > 解决方案 > 选项卡组件 - javascript 未定义错误

问题描述

您好,我不明白为什么我的标签组件不起作用。你看出什么不对了吗?

这是错误: Uncaught ReferenceError: openService is not defined


function openService(evt, serviceName) {
  // Declare all variables
  var i, tabcontent, tablinks;

  // Get all elements with class="tabcontent" and hide them
  tabcontent = document.getElementsByClassName("block-services");
  for (i = 0; i < tabcontent.length; i++) {
    tabcontent[i].style.display = "none";
  }

  // Get all elements with class="tablinks" and remove the class "active"
  tablinks = document.getElementsByClassName("li-services");
  for (i = 0; i < tablinks.length; i++) {
    tablinks[i].className = tablinks[i].className.replace(" active", "");
  }

  // Show the current tab, and add an "active" class to the button that opened the tab
  document.getElementById(serviceName).style.display = "block";
  evt.currentTarget.className += " active";
}

标签: javascript

解决方案


推荐阅读