-2

需要减去simpleCart_total&_SESSION['usr']['points']得到最终总数。基本上 javascript 值从数据库值中减去。

任何想法如何做到这一点?

<table><tbody>
<tr>
<td class='odd'><?php echo htmlentities($_SESSION['usr']['usr'], ENT_QUOTES, 'UTF-8');    ?></td>
<td class='even'>&nbsp;</td>
</tr>
<tr>
<td class='odd'>Your Value Points: </td>
<td class='even'><?php echo htmlentities($_SESSION['usr']['points'], ENT_QUOTES, 'UTF-8'); ?></td>
</tr>
<tr>
<td class='odd'>&nbsp;</td>
<td class='even'>&nbsp;</td>
</tr>

<tr><td class='odd'>Total Items: </td><td class='even'><span class='simpleCart_quantity'></span></td></tr>
<tr><td class='odd'>SubTotal: </td><td class='even'><span class='simpleCart_total'></span></td></tr>
<tr>
<td class='odd'>&nbsp;</td>
<td class='even'>&nbsp;</td>
</tr>
<tr>
<td class='odd'>Total</td>
<td class='even'>&nbsp;</td>
</tr>

</tbody>
</table>
4

1 回答 1

0

我只是在放置用户点的行中添加一个 id,在 simpleCart_total 中添加一个 id,在总结果 Your Value Points 中添加一个 id:    

    <tr><td class='odd'>Total Items: </td><td class='even'><span id='simpleCart_quantity' class='simpleCart_quantity'></span></td></tr>
    <tr><td class='odd'>SubTotal: </td><td class='even'><span id='simpleCart_total' class='simpleCart_total'>4</span></td></tr>
    <tr>
    <td class='odd'>&nbsp;</td>
    <td class='even'>&nbsp;</td>
    </tr>
    <tr>
    <td class='odd'>Total</td>
    <td class='even' id="total">&nbsp;</td>
    </tr>

    </tbody>
    </table>

然后每次添加或删除项目时调用此函数:

<script>
function total(){
    var points =  parseFloat(document.getElementById('points').innerHTML);
    var simpleCart_total = parseFloat(document.getElementById('simpleCart_total').innerHTML);

    var total = document.getElementById('total');

    total.innerHTML = points-simpleCart_total;

}
</script>

编辑

我不知道它是否会起作用,但你可以试试。备份您的文件 javascript/cart.js,然后找到并替换此代码:

for(var c=0;a.childNodes[c];c++){var d=a.childNodes[c];if(d.className&&d.className.match(/item_[^ ]+/)){var e=/item_[^ ]+/.exec(d.className)[0].split("_");if(e[1]=="add"||e[1]=="Add"){var f=[];f.push(d);var g=simpleCart.Shelf.addToCart(b.id);simpleCart.addEventToArray(f,g,"click");d.id=b.id}else{b[e[1]]=d}}

为了这:

for(var c=0;a.childNodes[c];c++){var d=a.childNodes[c];if(d.className&&d.className.match(/item_[^ ]+/)){var e=/item_[^ ]+/.exec(d.className)[0].split("_");if(e[1]=="add"||e[1]=="Add"){var f=[];f.push(d);var g=simpleCart.Shelf.addToCart(b.id);simpleCart.addEventToArray(f,g,"click");d.id=b.id}else{b[e[1]]=d}}var points=parseFloat(document.getElementById('points').innerHTML);var simpleCart_total = parseFloat(document.getElementById('simpleCart_total').innerHTML);var total=document.getElementById('total');total.innerHTML=points-simpleCart_total;

不要忘记将 id 'total' 添加到要显示结果的单元格中

于 2013-09-16T12:16:39.760 回答