我正在使用simplecart.js在我之前创建的网站上建立一个小商店。我有一个问题。只用一行代码显示整个购物车:
<div class="simpleCart_items"></div>
并且javascript打印表格,您在源代码中看不到它。但是,在 chrome 中检查元素是我的好朋友,创建的表看起来像这样:
<table>
<tbody>
<tr class="headerRow">
<th class="item-name">Tuote</th>
<th class="item-price">Hinta</th>
<th class="item-decrement"></th>
<th class="item-quantity">Määrä</th>
<th class="item-increment"></th>
<th class="item-total">Yhteensä</th>
<th class="item-remove"></th>
</tr>
<tr class="itemRow row-0 odd" id="cartItem_SCI-3">
<td class="item-name">Teipit (Valkoinen hiilikuitu)</td>
<td class="item-price">€48.00</td>
<td class="item-decrement">
<a href="javascript:;" class="simpleCart_decrement">-</a>
</td>
<td class="item-quantity">1</td>
<td class="item-increment">
<a href="javascript:;" class="simpleCart_increment">+</a>
</td>
<td class="item-total">€48.00</td>
<td class="item-remove">
<a href="javascript:;" class="simpleCart_remove">Poista</a>
</td>
</tr>
</tbody>
</table>
我希望它打印出这样的东西:
<table>
<tbody>
<tr class="headerRow">
<th class="item-name">Tuote</th>
<th class="item-price">Hinta</th>
<th class="item-decrement"></th>
<th class="item-quantity">Määrä</th>
<th class="item-increment"></th>
<th class="item-total">Yhteensä</th>
<th class="item-remove"></th>
</tr>
<tr class="itemRow row-0 odd" id="cartItem_SCI-3">
<td class="item-name">Teipit (Valkoinen hiilikuitu)</td>
<td class="item-price">€48.00</td>
<td class="item-decrement">
<a href="javascript:;" class="simpleCart_decrement">-</a>
</td>
<td class="item-quantity">1</td>
<td class="item-increment">
<a href="javascript:;" class="simpleCart_increment">+</a>
</td>
<td class="item-total">€48.00</td>
<td class="item-remove">
<a href="javascript:;" class="simpleCart_remove">Poista</a>
</td>
</tr>
<tr class="shippingtotal" id="shipping">
<td class="item-name">Shipping</td>
<td class="shipping-cost">€5.00</td>
<td class="item-decrement">
<a href="javascript:;" class="simpleCart_decrement">-</a>
</td>
<td class="item-quantity">1</td>
<td class="item-increment">
<a href="javascript:;" class="simpleCart_increment">+</a>
</td>
<td class="item-total">€48.00</td>
<td class="item-remove">
<a href="javascript:;" class="simpleCart_remove">Poista</a>
</td>
</tr>
</tbody>
</table>
所以,这里是 simplecart.js 本身: http: //pastebin.com/j5VKGkV1
我认为我应该在这部分代码中添加一些内容:
// write out cart
writeCart: function (selector) {
var TABLE = settings.cartStyle.toLowerCase(),
isTable = TABLE === 'table',
TR = isTable ? "tr" : "div",
TH = isTable ? 'th' : 'div',
TD = isTable ? 'td' : 'div',
cart_container = simpleCart.$create(TABLE),
header_container = simpleCart.$create(TR).addClass('headerRow'),
container = simpleCart.$(selector),
column,
klass,
label,
x,
xlen;
container.html(' ').append(cart_container);
cart_container.append(header_container);
// create header
for (x = 0, xlen = settings.cartColumns.length; x < xlen; x += 1) {
column = cartColumn(settings.cartColumns[x]);
klass = "item-" + (column.attr || column.view || column.label || column.text || "cell") + " " + column.className;
label = column.label || "";
// append the header cell
header_container.append(
simpleCart.$create(TH).addClass(klass).html(label));
}
// cycle through the items
simpleCart.each(function (item, y) {
simpleCart.createCartRow(item, y, TR, TD, cart_container);
});
return cart_container;
},
// generate a cart row from an item
createCartRow: function (item, y, TR, TD, container) {
var row = simpleCart.$create(TR).addClass('itemRow row-' + y + " " + (y % 2 ? "even" : "odd")).attr('id', "cartItem_" + item.id()),
j,
jlen,
column,
klass,
content,
cell;
container.append(row);
// cycle through the columns to create each cell for the item
for (j = 0, jlen = settings.cartColumns.length; j < jlen; j += 1) {
column = cartColumn(settings.cartColumns[j]);
klass = "item-" + (column.attr || (isString(column.view) ? column.view : column.label || column.text || "cell")) + " " + column.className;
content = cartCellView(item, column);
cell = simpleCart.$create(TD).addClass(klass).html(content);
row.append(cell);
}
return row;
}
});
但是什么?运费可以这样显示:
<span class="simpleCart_shipping"></span>
我试过在购物车之后添加它,但它看起来有点傻。
更新:这是一个没有 mofication 的示例(之前): 这就是它应该是什么样的..