JavaScript-在HTML表格中动态添加表格行

JavaScript-在HTML表格中动态添加表格行,javascript,html-table,Javascript,Html Table,我有以下脚本,希望通过该脚本在我的网站上的HTML表中动态添加行: <script> var globalIterationVariable = 0; document.onload = $globalIterationVariable = 1; $('document').ready(function() { $('.add_another').click(function() { var globalIterationVariable; var new

我有以下脚本,希望通过该脚本在我的网站上的HTML表中动态添加行:

<script>
var globalIterationVariable = 0;
document.onload = $globalIterationVariable = 1;
$('document').ready(function() {
  $('.add_another').click(function() {
      var globalIterationVariable;
      var newRowVariable = '<tr><td><center><input name="nazovPolozky';
      newRowVariable.append(String($globalIterationVariable));
      newRowVariable.append(' type="text"></center></td> <td><center><input name="pocetPolozky');
      newRowVariable.append(String($globalIterationVariable));
      newRowVariable.append('" type="number" step="1" min="1"></center></td> <td><center><input name="jednotkovaCenaPolozky');
      newRowVariable.append(String($globalIterationVariable));
      newRowVariable.append('" type="number" step="0.01" min="0.01"></center></td></tr>');
      alert(String(newRowVariable));
      $("#tbl").append(String(newRowVariable));
      globalIterationVariable++
   });
});
</script>
有谁能帮我把这个剧本写出来吗

多谢各位

p.S.:当我按下网站上的某个特定按钮,该按钮上有一个class='button add_other'

这是一个字符串时,就会启动此脚本

 var newRowVariable = '<tr><td><center><input name="nazovPolozky';
var newRowVariable='您应该将newRowVariable定义为DOM元素->

const newRowVariable=document.createElement('tr')
然后将内容(您的字符串)附加到它->

newRowVariable.innerHTML=`
请注意,我使用的是``而不是''或'',这是因为您可以在这样的字符串中使用javascript变量->

const text=“世界”
const superString=`Hello${text}`
//console.log(超级字符串)将返回“Hello World”

当您是一个完整的用户时,Jquery可能会很有用,但您很快就会发现使用纯javascript更简单;)

字符串附加?不知道你从哪里弄来的。与错误状态一样,字符串没有附加。了解字符串模板文本。这将使它更易于阅读。
concat
而不是
append
,因为
newRowVariable
是一个字符串,而不是一个HTMLelementdocument.onload=$GlobalOperationVariable=1;document.onload=$globalIterationVariable=1;这应该在页面加载后启动一个全局变量。谢谢!这管用!我还有一个问题,为什么GlobalOperationVariable++不总是给我它的值+1?更新:Nevermind,我通过:$globalIterationVariable++将其修复为全局变量,它必须在局部范围之外声明。如在脚本顶部。谢谢!这似乎很有趣,值得我学习:)
 var newRowVariable = '<tr><td><center><input name="nazovPolozky';
 var newRowVariable = $('<tr><td><center><input name="nazovPolozky');
 var newRowVariable = '<tr><td><center><input name="nazovPolozky';
 newRowVariable += "/></td></tr>";