猿问

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

我正在为我的 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> 


侃侃无极
浏览 184回答 2
2回答

牛魔王的故事

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

LEATH

在您的代码中,您只对第一列进行排序.. 可以吗?&nbsp; &nbsp;const Cmds = [&nbsp; &nbsp; &nbsp; &nbsp;"/server",&nbsp; &nbsp; &nbsp; &nbsp;"/msg",&nbsp; &nbsp; &nbsp; &nbsp;"/r",&nbsp; &nbsp; &nbsp; &nbsp;"/island,/is",&nbsp; &nbsp; &nbsp; &nbsp;"/towny,/t",&nbsp; &nbsp; &nbsp; &nbsp;"/nation,/n",&nbsp; &nbsp; &nbsp; &nbsp;"/echest",&nbsp; &nbsp; &nbsp; &nbsp;"/craft,/wb,/workbench",&nbsp; &nbsp; &nbsp; &nbsp;"/tpa",&nbsp; &nbsp; &nbsp; &nbsp;"/tpahere",&nbsp; &nbsp; &nbsp; &nbsp;"/tpaccept"&nbsp; &nbsp;];&nbsp; &nbsp;const Args = [&nbsp; &nbsp; &nbsp; &nbsp;"(servername)",&nbsp; &nbsp; &nbsp; &nbsp;"(playname) (message)",&nbsp; &nbsp; &nbsp; &nbsp;"(message)",&nbsp; &nbsp; &nbsp; &nbsp;"(optional)",&nbsp; &nbsp; &nbsp; &nbsp;"(optional)",&nbsp; &nbsp; &nbsp; &nbsp;"(optional)",&nbsp; &nbsp; &nbsp; &nbsp;"N/A",&nbsp; &nbsp; &nbsp; &nbsp;"N/A",&nbsp; &nbsp; &nbsp; &nbsp;"(playername)",&nbsp; &nbsp; &nbsp; &nbsp;"(playername)",&nbsp; &nbsp; &nbsp; &nbsp;"N/A"&nbsp; &nbsp;];&nbsp; &nbsp;const Usage = [&nbsp; &nbsp; &nbsp; &nbsp;"Used to switch between the hub and gamemodes.",&nbsp; &nbsp; &nbsp; &nbsp;"Used to send a pm to a player.",&nbsp; &nbsp; &nbsp; &nbsp;"Sends a pm to the player you last sent/recieved a pm from.",&nbsp; &nbsp; &nbsp; &nbsp;"Without args opens gui. With args open a specific section.",&nbsp; &nbsp; &nbsp; &nbsp;"Without args displays town info. With args you can config your town.",&nbsp; &nbsp; &nbsp; &nbsp;"Without args displays nation info. With args you can config your nation.",&nbsp; &nbsp; &nbsp; &nbsp;"Open your enderchest via a command.",&nbsp; &nbsp; &nbsp; &nbsp;"Open a crafting table via a command.",&nbsp; &nbsp; &nbsp; &nbsp;"Sends a request to teleport to a player.",&nbsp; &nbsp; &nbsp; &nbsp;"Sends a request to teleport to a player to you.",&nbsp; &nbsp; &nbsp; &nbsp;"Accepts the last pending teleport request."&nbsp; &nbsp;];&nbsp; &nbsp;const Server = [&nbsp; &nbsp; &nbsp; &nbsp;"*",&nbsp; &nbsp; &nbsp; &nbsp;"*",&nbsp; &nbsp; &nbsp; &nbsp;"*",&nbsp; &nbsp; &nbsp; &nbsp;"Skyblock",&nbsp; &nbsp; &nbsp; &nbsp;"Towny",&nbsp; &nbsp; &nbsp; &nbsp;"Towny",&nbsp; &nbsp; &nbsp; &nbsp;"Towny/Skyblock",&nbsp; &nbsp; &nbsp; &nbsp;"Towny/Skyblock",&nbsp; &nbsp; &nbsp; &nbsp;"Towny/Skyblock",&nbsp; &nbsp; &nbsp; &nbsp;"Towny/Skyblock",&nbsp; &nbsp; &nbsp; &nbsp;"Towny/Skyblock"&nbsp; &nbsp;];&nbsp; &nbsp;const Rank = [&nbsp; &nbsp; &nbsp; &nbsp;"*",&nbsp; &nbsp; &nbsp; &nbsp;"*",&nbsp; &nbsp; &nbsp; &nbsp;"*",&nbsp; &nbsp; &nbsp; &nbsp;"* (Skyblock owner)",&nbsp; &nbsp; &nbsp; &nbsp;"* (Town owner)",&nbsp; &nbsp; &nbsp; &nbsp;"* (Town owner)",&nbsp; &nbsp; &nbsp; &nbsp;"Donator,Donator+,DonatorPro,*Staff",&nbsp; &nbsp; &nbsp; &nbsp;"Donator,Donator+,DonatorPro,*Staff",&nbsp; &nbsp; &nbsp; &nbsp;"*",&nbsp; &nbsp; &nbsp; &nbsp;"*",&nbsp; &nbsp; &nbsp; &nbsp;"*"&nbsp; &nbsp;];&nbsp; &nbsp;Cmds.sort().reverse();&nbsp; &nbsp;var table = document.getElementById("cmdlist");&nbsp; &nbsp;for (let i = 0; i < Cmds.length; i++) {&nbsp; &nbsp; &nbsp; &nbsp;var row = table.insertRow(i+1);&nbsp; &nbsp; &nbsp; &nbsp;[&nbsp; &nbsp; &nbsp; &nbsp; Cmds,&nbsp; &nbsp; &nbsp; &nbsp; Args,&nbsp; &nbsp; &nbsp; &nbsp; Usage,&nbsp; &nbsp; &nbsp; &nbsp; Server,&nbsp; &nbsp; &nbsp; &nbsp; Rank&nbsp; &nbsp; &nbsp; ].forEach((column, index) => {&nbsp; &nbsp; &nbsp; &nbsp; row.insertCell(index).innerHTML = column[i]&nbsp; &nbsp; &nbsp; })&nbsp; }table, th, td {&nbsp; border: 1px dotted #cdcdcd;}tr:nth-child(even) {&nbsp; background: #eee}tr:nth-child(odd) {&nbsp; background: #FFF}th {&nbsp; background-color: #000;&nbsp; color: white;}<table id="cmdlist">&nbsp; &nbsp; <tr>&nbsp; &nbsp; &nbsp; &nbsp; <th>Command</th>&nbsp; &nbsp; &nbsp; &nbsp; <th><i style="color: rgb(0,255,255);">Tuple</i> Arguments</th>&nbsp; &nbsp; &nbsp; &nbsp; <th>Usage</th>&nbsp; &nbsp; &nbsp; &nbsp; <th>Server(s)</th>&nbsp; &nbsp; &nbsp; &nbsp; <th>Rank</th>&nbsp; &nbsp; </tr></table>
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答