87,907
社区成员
发帖
与我相关
我的任务
分享
你在一个函数内访问另一个函数内的局部变量当然不行了,把两个函数合为一个即可
function addproduct(){
var pname = $("#pname").html();
var price = document.getElementById("price").innerText;
var quantity = document.getElementById("quantity").innerText;
var stock = document.getElementById("stock").innerText;
var table = document.getElementById("cart");
var row = table.insertRow(-1);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
var cell4 = row.insertCell(3);
var cell5 = row.insertCell(4);
cell1.innerText = pname;
cell2.innerText = price;
cell3.innerText = quantity;
cell4.innerText = stock;
cell5.innerText = price;
}