rookie shopping cart won't add new items only replace 1st item when clicking add button
instead of adding a new table row, the table row gets replaced
itemRow = "<tr><td class='txt'>" + somevalue + "</td><td>" + somevalue + "</td><td>" + somevalue + "</td><td class='nr'>" + somevalue + "</td></tr>"
table = "<table>" + itemRow +"</table>"
div.innerHTML = table;
(note I cannot 开发者_Go百科use jQuery or any other library for this assignment)
You have to append the new row instead of replacing it. The question basically answers itself:
//In the beginning
var allRows = '';
//To add a new row
allRows += "the new row";
table = "<table>" + allRows + "<table>"
You might want to check some DOM manipularion methods as well.
精彩评论