求助js购物车代码!要能点击 添加按钮 就直接在购物车显示出来!可以修改数量!

JavaScript014

求助js购物车代码!要能点击 添加按钮 就直接在购物车显示出来!可以修改数量!,第1张

<script language='javascript'>

function checkSum()

{

var sum = 0

for(var i=0i<document.form1.elements["writer"].lengthi++)

{

if(document.form1.elements["writer"][i].checked)

{

sum = sum +parseInt(document.form1.elements["writer"][i].value)

}

}

totalprice.innerText = sum +" 元"

}

</script>

<form method=post name=form1>

<input type="checkbox" name=writer value="34" onclick="checkSum()">韩国耳饰tm56(34元)<br>

<input type="checkbox" name=writer value="46" onclick="checkSum()">纯银吊坠tc34(46元)<br>

<input type="checkbox" name=writer value="30" onclick="checkSum()">黄莺手镯ta345(30元)<br>

<input type="checkbox" name=writer value="40" onclick="checkSum()">翡翠玉镯1346(40元)<br>

<input type="checkbox" name=writer value="50" onclick="checkSum()">天涯耳饰1233(50元)<br>

<br>

总价为:<span id="totalprice">0 元</span>

</form>

楼主是想要点击合计就是出数值还是什么?如果说点击合计就算出值的话如下

<table width="400" border="1">

    <tr>

     <th rows="5">简易购物车</th>

    </tr>

    <tr>

     <td>商品名称</td>

     <td>数量(件)</td>

     <td>单价(美元)</td>

     <td>运费(美元)</td>

     <td><button onclick="fun()">合计</button></td>

    </tr>

    <tr>

     <td><input type="text" name="goodsName" /></td>

     <td><input type="text" name="num" id="num" /></td>

     <td><input type="text" name="price" id="price" /></td>

     <td><input type="text" name="freight" id="freight" /></td>

     <td><input type="text" name="total" id="total" /></td>

    </tr>

</table>

<script>

function fun(){

var num = document.getElementById("num").value

var price = document.getElementById("price").value

        var freight = parseInt(document.getElementById("freight").value)

        var total = (price * num) + freight

        document.getElementById("total").value = total

}

</script>