当前位置: 首页> 汽车> 行情 > 温州网站定制_开发公众号的体会_全国疫情最新_外链怎么发

温州网站定制_开发公众号的体会_全国疫情最新_外链怎么发

时间:2025/7/9 16:33:31来源:https://blog.csdn.net/lljss1980/article/details/142482522 浏览次数: 0次
温州网站定制_开发公众号的体会_全国疫情最新_外链怎么发
<!DOCTYPE html>  
<head>  
<meta charset="UTF-8">  
<title>Dynamic Tabs with Table Data</title>  
<style>  /* 简单的样式 */    .tab-content {    display: none;    border: 1px solid #ccc;    padding: 1px;    margin-top: 0px;    }    .tab-content.active {    display: block;    }    button {  margin-right: 0px; /* 添加一些间隔 */  background-color: transparent; /* 初始背景色透明 */  border: 1px solid #ccc; /* 明确边框样式和颜色 */cursor: pointer; /* 鼠标悬停时显示手指形状 */  padding: 5px 10px; /* 增加内边距以便点击 */  }  .active-tab {    background-color: rgb(77, 218, 223); /* 选中时背景色变为蓝色 */  color: white; /* 文本颜色变为白色,以便在蓝色背景上可见 */border-color: rgb(47, 178, 183); /* 更改边框颜色以匹配背景色 */   }    table {    width: 100%;    border-collapse: collapse;    }    th, td {    border: 1px solid #ddd;    padding: 8px;    text-align: left;    }    th {    background-color: #f2f2f2;    }  
</style>  
</head>  
<body>  
<div id="tabs">  <!-- 选项卡头部将在这里动态生成 -->  
</div>  
<div id="tab-contents">  <!-- 选项卡内容(表格)将在这里动态生成 -->  
</div>  <script>  
// 假设这是从后端获取的数据  
const data = {  "datasets": [  {  "name": "Dataset 1",  "data": [  { "num1": 1234, "num2": 5678, "status1": "on", "status2": "active" },  // 更多数据...  ]  },  {  "name": "Dataset 2",  "data": [  { "num1": 3456, "num2": 7890, "status1": "off", "status2": "inactive" },  // 更多数据...  ]  }  ]  
};  // 动态生成选项卡头部和内容  
const tabsDiv = document.getElementById('tabs');  
const tabContentsDiv = document.getElementById('tab-contents');  // 动态生成选项卡头部和内容  
data.datasets.forEach((dataset, index) => {  const tabButton = document.createElement('button');  tabButton.textContent = `Tab ${index + 1} (${dataset.name})`;  tabButton.onclick = () => {  // 移除所有按钮的.active-tab类  const allTabs = document.querySelectorAll('#tabs button');  allTabs.forEach(tab => tab.classList.remove('active-tab'));  // 为当前点击的按钮添加.active-tab类  tabButton.classList.add('active-tab');  // 显示对应的选项卡内容  showTabContent(index);  };  tabsDiv.appendChild(tabButton); const tabContent = document.createElement('div');  tabContent.className = 'tab-content';  // 创建表格  const table = document.createElement('table');  const thead = table.createTHead();  const headerRow = thead.insertRow();  ['Num1', 'Num2', 'Status1', 'Status2'].forEach(text => {  let th = document.createElement('th');  th.textContent = text;  headerRow.appendChild(th);  });  const tbody = table.createTBody();  dataset.data.forEach(item => {  let row = tbody.insertRow();  ['num1', 'num2', 'status1', 'status2'].forEach(key => {  let cell = row.insertCell();  cell.textContent = item[key];  });  });  tabContent.appendChild(table);  tabContentsDiv.appendChild(tabContent);  
});  // 默认显示第一个选项卡的内容和按钮  
if (data.datasets.length > 0) {  const firstTabButton = tabsDiv.querySelector('button');  firstTabButton.classList.add('active-tab');  const firstTabContent = tabContentsDiv.querySelector('.tab-content');  firstTabContent.classList.add('active');  
}  function showTabContent(index) {  const tabContents = document.querySelectorAll('.tab-content');  tabContents.forEach(tabContent => tabContent.classList.remove('active'));  tabContents[index].classList.add('active');  
}  
</script>  
</body>  
</html>

在这里插入图片描述

关键字:温州网站定制_开发公众号的体会_全国疫情最新_外链怎么发

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: