为了账号安全,请及时绑定邮箱和手机立即绑定

对表格进行排序但表格标题已损坏

对表格进行排序但表格标题已损坏

侃侃无极 2022-10-21 09:45:25
我正在为我的 Minecraft 服务器创建一个帮助部分,以便玩家可以查看命令及其用法。我对它们进行了排序,以使其在尝试查找命令时更有意义。出于某种原因,它通过 Cmds 组织表格,但将表格标题放在底部。我如何让它跳过这个?由于某种原因,还有一个空白条目。<table id="cmdlist">    <tr>        <th>Command</th>        <th><i style="color: rgb(0,255,255);">Tuple</i> Arguments</th>        <th>Usage</th>        <th>Server(s)</th>        <th>Rank</th>    </tr>    <td>    </td></table><script type="text/javascript">    var Cmds,Args,Usage,Server,Rank;    Cmds = ["/server","/msg","/r","/island,/is","/towny,/t","/nation,/n","/echest","/craft,/wb,/workbench","/tpa","/tpahere","/tpaccept"];    Args = ["(servername)","(playname) (message)","(message)","(optional)","(optional)","(optional)","N/A","N/A","(playername)","(playername)","N/A"]                Usage = ["Used to switch between the hub and gamemodes.",                "Used to send a pm to a player.",                "Sends a pm to the player you last sent/recieved a pm from.",                "Without args opens gui. With args open a specific section.",                "Without args displays town info. With args you can config your town.",                "Without args displays nation info. With args you can config your nation.",                "Open your enderchest via a command.",                "Open a crafting table via a command.",                "Sends a request to teleport to a player.",                "Sends a request to teleport to a player to you.",                "Accepts the last pending teleport request."                ]    }</script> 
查看完整描述

2 回答

?
牛魔王的故事

TA贡献1830条经验 获得超3个赞

table.insertRow(0)会将您的行添加到表格的开头,将之前的所有行向下推(包括您的表格标题)。你的意思是做,这会在表的末尾table.insertRow(-1)添加一行吗?


插入行引用


查看完整回答
反对 回复 2022-10-21
?
LEATH

TA贡献1936条经验 获得超7个赞

在您的代码中,您只对第一列进行排序.. 可以吗?


   const Cmds = [

       "/server",

       "/msg",

       "/r",

       "/island,/is",

       "/towny,/t",

       "/nation,/n",

       "/echest",

       "/craft,/wb,/workbench",

       "/tpa",

       "/tpahere",

       "/tpaccept"

   ];

   const Args = [

       "(servername)",

       "(playname) (message)",

       "(message)",

       "(optional)",

       "(optional)",

       "(optional)",

       "N/A",

       "N/A",

       "(playername)",

       "(playername)",

       "N/A"

   ];

   const Usage = [

       "Used to switch between the hub and gamemodes.",

       "Used to send a pm to a player.",

       "Sends a pm to the player you last sent/recieved a pm from.",

       "Without args opens gui. With args open a specific section.",

       "Without args displays town info. With args you can config your town.",

       "Without args displays nation info. With args you can config your nation.",

       "Open your enderchest via a command.",

       "Open a crafting table via a command.",

       "Sends a request to teleport to a player.",

       "Sends a request to teleport to a player to you.",

       "Accepts the last pending teleport request."

   ];

   const Server = [

       "*",

       "*",

       "*",

       "Skyblock",

       "Towny",

       "Towny",

       "Towny/Skyblock",

       "Towny/Skyblock",

       "Towny/Skyblock",

       "Towny/Skyblock",

       "Towny/Skyblock"

   ];

   const Rank = [

       "*",

       "*",

       "*",

       "* (Skyblock owner)",

       "* (Town owner)",

       "* (Town owner)",

       "Donator,Donator+,DonatorPro,*Staff",

       "Donator,Donator+,DonatorPro,*Staff",

       "*",

       "*",

       "*"

   ];


   Cmds.sort().reverse();

   var table = document.getElementById("cmdlist");

   for (let i = 0; i < Cmds.length; i++) {

       var row = table.insertRow(i+1);

       [

        Cmds,

        Args,

        Usage,

        Server,

        Rank

      ].forEach((column, index) => {

        row.insertCell(index).innerHTML = column[i]

      })

  }

table, th, td {

  border: 1px dotted #cdcdcd;

}


tr:nth-child(even) {

  background: #eee

}

tr:nth-child(odd) {

  background: #FFF

}


th {

  background-color: #000;

  color: white;

}

<table id="cmdlist">

    <tr>

        <th>Command</th>

        <th><i style="color: rgb(0,255,255);">Tuple</i> Arguments</th>

        <th>Usage</th>

        <th>Server(s)</th>

        <th>Rank</th>

    </tr>

</table>


查看完整回答
反对 回复 2022-10-21
  • 2 回答
  • 0 关注
  • 183 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号