Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/454.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Javascript创建大型HTML表和重复单元格_Javascript_Html_Html Table_Cell_Persistent - Fatal编程技术网

使用Javascript创建大型HTML表和重复单元格

使用Javascript创建大型HTML表和重复单元格,javascript,html,html-table,cell,persistent,Javascript,Html,Html Table,Cell,Persistent,我确信这必须在某个地方记录下来,但我对html太陌生了,以至于我不知道该在哪里查找,所以如果有什么明显的问题,请随时指导我正确阅读。请注意,我用几种语言编写代码,但主要是python或LaTeX之类的东西,与html完全不同。我已经在底部列出了我的尝试,但是我尝试在我的设计设置和遇到的问题方面列出了我所能做到的。对于所列问题的任何解决方案,我们将不胜感激:) 设置 我需要形成巨大的信息表,这些信息将根据另一个网页上给出的JSON字符串填充。我目前正在使用javascript解析JSON字符串,并

我确信这必须在某个地方记录下来,但我对html太陌生了,以至于我不知道该在哪里查找,所以如果有什么明显的问题,请随时指导我正确阅读。请注意,我用几种语言编写代码,但主要是python或LaTeX之类的东西,与html完全不同。我已经在底部列出了我的尝试,但是我尝试在我的设计设置和遇到的问题方面列出了我所能做到的。对于所列问题的任何解决方案,我们将不胜感激:)

设置

我需要形成巨大的信息表,这些信息将根据另一个网页上给出的JSON字符串填充。我目前正在使用javascript解析JSON字符串,并形成一个我自己的全局对象,该对象包含所有相关信息(用户将插入的JSON字符串非常大,我只需要它的一小部分)。创建的对象具有以下形式:

  cruData = {hero:[{"cruID":0,"EP":0,"Owned":"No","GearName1":"Empty","GearRarity1":"Empty","GearName2":"Empty","GearRarity2":"Empty","GearName3":"Empty","GearRarity3":"Empty"}]}
cruID从0迭代到103(计划在某个点上使其至少高出几百)。所有字符串都将填充字符串,EP/ID为真数字

建议的设置:

我最初的计划是在单独的web页面上预先创建(空白)表结构,然后在获取JSON文件并将其解析为cruData对象之后,在用户访问该表时,在页面加载时用相关信息(目前技术上ID为1到103,该表中没有0 ID)填充该表

问题:

1) 对于这种在页面加载时形成表的方法,我关心的是表是相当大的,我真的不希望在每次页面加载时都形成表。有没有一种方法可以在本地保存它,这样它就可以形成一次,然后放到缓存中

2) 假设预先格式化表格真的是个好主意(请随意告诉我我这么想很愚蠢),我将有350多个单元格(所有“稀有”单元格),它们都是相同的下拉框。因此,我想为下拉选择列表中的单元格创建一个类类型,但不知道如何在“样式”部分中实现。我可以得到一个特定的td来工作,但没有一个td来工作。同样,我确信这是因为我不太理解定义类或样式部分是如何工作的(我以前没有使用过类继承系统编码)

具体来说,我希望在这个100多行表格的每一行的3个不同单元格中都有一个下拉框。它们都是相同的下拉选择。要做到这一点,表格会更好吗?有没有一种方法可以在一个类中定义一次下拉选择,然后只指向每个单元格中的类,这样我就不必在每行的3个单元格中重新添加选择选项

3) 我希望每一行的稀有单元格和EP单元格都可以由人编辑,并将新值保存到其他地方进行计算。我的想法是将cruData对象复制到用于计算的cruComp对象,然后让它被播放器输入覆盖;这样,我就可以在表格页面上添加一个“重置”按钮,在用户后悔之后修复一切:)

4) 我想给表中的行块上色,这些行块对应于我记录数据的游戏中的某些内容。现在,我需要每5行在标题后以一种颜色被分块在一起,但这5行可能会普遍更改为另一个数字。有没有办法设置一个动态变量,这样我就可以改变一个数字而不是一堆?在我下面的尝试中,它也适用于第一行,比如50-70行,然后开始有各种奇怪的行为,但我不明白为什么? [已解决,找到问题所在的thead tbody标签]

5) 这不是一个真正的问题,但是,有没有一种方法可以在不手动创建每个行的情况下创建x行?唯一的问题是,下面给出的示例中的ID编号将包含所有编号1-103+,但不按该顺序排列。我想我可以做一些向量,让数字按正确的顺序排列,然后从向量中提取连续的数字,以便按顺序排列,但我不知道是否可以使用FOR循环创建行

谢谢你的帮助

我的尝试:警告,我相信这会让任何知道自己在做什么的人死在自己的内心,因为我一直在说我真的不知道我在用这种语言做什么。因此,我从一个愚蠢的项目开始,在实践中学习:)


COTLI计算器和Ref
函数加载_数据(){
var i=0;
/*
布什杀手
空白
空白
空白
空白
空白
空白
空白
空白
*/
对于(i=1;i<!DOCTYPE html>
<html>
<head>
  <title>COTLI Calculator and Ref</title>
<!--  <link rel="stylesheet" href="StyleRef.css"> -->

 <script>
   function Load_Data() {
    var i = 0;

/*
         <td>The Bush Whacker</td>
         <td id="CrEP_1">Blank</td>
         <td id="CrGN1_1">Blank</td>
         <td id="CrGR1_1">Blank</td>
         <td id="CrGN2_1">Blank</td>
         <td id="CrGR2_1">Blank</td>
         <td id="CrGN3_1">Blank</td>
         <td id="CrGR3_1">Blank</td>
         <td id="CrUnLock_1">Blank</td>
*/
  for (i = 1; i < lootTable.hero.length; i++) {
  "crEP_"+i = cruData.hero[i].EP;
  };
 }

   window.onload = Load_Data;

 </script>


</head>


<body style="background-color:lightgrey; text-align:center;">


  <style>
<!-- Below is the color coding for the rows broken into batches of 4 bench slots at a time. The offset value is because of how the rows are counted and the "header" row. -->
<!--  tr:nth-child(35n+1) {background-color: #4682b4;} -->
<!--  tr:nth-child(21n+1) {background-color: #e36f8a;} -->

  tr:nth-child(20n+2) {background-color: #4682b4;}
  tr:nth-child(20n+3) {background-color: #4682b4;}
  tr:nth-child(20n+4) {background-color: #4682b4;}
  tr:nth-child(20n+5) {background-color: #4682b4;}
  tr:nth-child(20n+6) {background-color: #4682b4;}

  tr:nth-child(20n+7) {background-color: #3abda0;}
  tr:nth-child(20n+8) {background-color: #3abda0;}
  tr:nth-child(20n+9) {background-color: #3abda0;}
  tr:nth-child(20n+10) {background-color: #3abda0;}
  tr:nth-child(20n+11) {background-color: #3abda0;}

  tr:nth-child(20n+12) {background-color: #e09e87;}
  tr:nth-child(20n+13) {background-color: #e09e87;}
  tr:nth-child(20n+14) {background-color: #e09e87;}
  tr:nth-child(20n+15) {background-color: #e09e87;}
  tr:nth-child(20n+16) {background-color: #e09e87;}

  tr:nth-child(20n+17) {background-color: #93b881;}
  tr:nth-child(20n+18) {background-color: #93b881;}
  tr:nth-child(20n+19) {background-color: #93b881;}
  tr:nth-child(20n) {background-color: #93b881;}
  tr:nth-child(20n+1) {background-color: #93b881;}


    table {
      border-collapse: collapse;
      border: 5px solid black;
      tex-align:center;
    }
    th {
      padding: 20px;
      border: solid black 3px;
    }

    td {
      padding: 20px;
      border: solid black 1px;
    }

    td.rarity {
      <select>
        <option value="volvo">Volvo</option>
        <option value="saab">Saab</option>
        <option value="mercedes">Mercedes</option>
        <option value="audi">Audi</option>
      </select>
    }

  </style>

  <h1>
    Crusader Table
  </h1>

  <table align="center">
     <tr style="background-color:#e36f8a; text-align:center;">
         <th>Crusader Name</th>
         <th>EP</th>
         <th>Gear 1 Name</th>
         <th>Gear 1 Rarity</th>
         <th>Gear 2 Name</th>
         <th>Gear 2 Rarity</th>
         <th>Gear 3 Name</th>
         <th>Gear 3 Rarity</th>
         <th>Unlocked</th>
    </tr>
    <!-- Below is the master table for Crusaders. Tags are: CrEP_# for EP, CrGN1_# for Gear 1 name, CrGR1_# for Gear 1 Rarity (similarly gear 2 and 3) and CrUnlock_# for unlock, where # is Crusader ID. -->

<!-- Bench One

The Bush Whacker - 1
RoboRabbit - 38
Graham The Driver - 66
Warwick the Warlock - 75
Slisiblyp, the Alien Scientist - 89
-->
<tr>
     <td>The Bush Whacker</td>
     <td id="CrEP_1" value=CruData.hero[1].EP> </td>
     <td id="CrGN1_1">Blank</td>
     <td class="rarity" id="CrGR1_1"></td>
     <td id="CrGN2_1">Blank</td>
     <td id="CrGR2_1">Blank</td>
     <td id="CrGN3_1">Blank</td>
     <td id="CrGR3_1">Blank</td>
     <td id="CrUnLock_1">Blank</td>
</tr>