开发者

rookie shopping cart won't add new items only replace 1st item when clicking add button

开发者 https://www.devze.com 2023-02-10 08:33 出处:网络
instead of adding a new table row, the table row gets replaced itemRow = \"<tr><td class=\'txt\'>\" + somevalue + \"</td><td>\" + somevalue + \"</td><td>\" + som

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消