我无法让代码工作。有人可以指出我做错了什么吗?我只想使用JavaScript将输入打印到表格中。添加html输入到表
HTML
Item:
Quantity:
Price: AUD
Item | Quantity | Price |
---|
的JavaScript
function addRow() {
"use strict";
var table = document.getElementById("table");
var td1 = document.createElement("td");
var td2 = document.createElement("td");
var td3 = document.createElement("td");
td1.innerHTML = document.getElementById("item").value;
td2.innerHTML = document.getElementById("quantity").value;
td3.innerHTML = document.getElementById("price").value;
row.appendChild(td1);
row.appendChild(td2);
row.appendChild(td3);
table.children[0].appendChild(row);
});
+0
哪里变量'row'从何而来?您的Java脚本控制台(例如Firebug)会在执行代码时显示这是一个错误。 –
+0
您没有名为'row'的对象。 –
+0
什么是''使用严格的“;'和你的函数在哪里关闭'}'括号。 –