Jquery HTML 或 AFTER 或 APPEND with HTML table 标签

问题描述

https://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_html_after2

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
function afterText() {
  $("#tblGrid").html("<td>NameName2</td><td>Budget Value 2</td></tr><tr><td>NameName3</td><td>Budget Value 3</td>");
}
</script>
</head>
<body>
<table>
 <tbody>
 <th><h4>Name Heading</h4></th>
 <th>
    <table>
        <thead>
        <tr>
            <th>Budget Heading</th>
        </tr>
        </thead>
   </table>
  </th>
     
 <tr id="tblGrid"></tr>
 <tr><td>NameName1</td><td>Budget Value 1</td></tr>
 </tbody>
</table>

<button onclick="afterText()">Button</button>

</body>
</html>

点击按钮后输出是这样的:

名称标题预算标题

NameName3 预算值 3

NameName1 预算值 1

按钮

您能否帮助理解数字为“2”的值的去向?

预期输出:

名称标题预算标题

NameName2 预算值 2

NameName3 预算值 3

NameName1 预算值 1

按钮

此外,每次我们点击按钮时,不应该追加 2 和 3,而是清除旧的迭代值。请提出建议!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)