h5 购物车动态加载页面及动态计算价格js

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1,user-scalable=no">
    <title>购买清单</title>

    <script type="text/javascript" src="../../js/jquery.min.js"></script>
    <style>
        .content{
            width: 100Px;
            height: 100px;
            background: deepskyblue;
        }
        .right-div{
            width: 100Px;
            height: 100px;
            background: deepskyblue;
            text-align: center;
        }
    </style>
</head>

<body style="background: gainsboro">

<script>
    //全选
    function checkAll() {
        //用getElementsByName作为标示
        var names=document.getElementsByName('gonggaoid');
        var singAll=document.getElementById('singAll');

        var len=names.length;
        var  sum = 0;
        for(var i=0;i<len;i++){
            if(singAll.checked){
                names[i].checked=true;
            }
            if(!singAll.checked){
                names[i].checked=false;
            }
        }
        dataCal();
    }

//单选
    function dataCal(){
        var sum=0;
        var obj=document.getElementsByName("priceid");
        var names=document.getElementsByName('gonggaoid');
//取得页面所有的items复选框对象
        for(var i=0;i<names.length;i++)
        {
            if(names[i].checked){
                sum= sum + parseFloat(obj[i].innerText);
            }
        }
        checkOne();
        document.getElementById("Allcount").innerHTML = sum+".0  元";
    }


//全选
    function checkOne() {
        //每个checkbox
        var names=document.getElementsByName('gonggaoid');
        //全选的按钮
        var all = document.getElementById('singAll');

        var i=0;
        for (i;i<names.length;i++){
            if(!names[i].checked){
                all.checked = false;
                break;
            }
        }
        if(i == names.length)
        {
            all.checked = true;
        }
    }

    function Success() {
        alert("时间到了");

    }


</script>

<script>
    var test = function () {
        var _course_ids = new Array();
        _course_ids.push("1");
        _course_ids.push("2");
        var _param = new Object();
        _param["course_ids"] = _course_ids;
        _param["token"] = "19931701234085720161129143619";
        console.log(JSON.stringify(_param))
        $.ajax({
            type: "post",
            url: "http://*******************",
            data: {"param" : JSON.stringify(_param)},
            dataType: "json",
            success: function (data) {
                console.log(data);
                var _size = data.courseDOs.length;
                document.write("<table style='text-align: center  ;font-size: 16px;border-collapse: collapse;width: 100%;align=center;position: relative;top: 64px' >")
                document.write("<caption style='font-size: 18px ;height: 40px ;color: dodgerblue;font-family: 楷体'> 购买清单 ")
                document.write("</caption>");
                document.write("<tr style='font-size: 15px;color: dodgerblue;line-height: 30px ;border: 1px solid gainsboro; border-radius:5px 5px 0 0;' >")

                document.write("<th>");
                document.write("<input type='checkbox' id='singAll' οnclick='checkAll()'style='text-align: left ;'> 全选             " );
                document.write("</th>");

                document.write("<th style='text-align: left'>");
                document.write("商品详情" );
                document.write("</th>")

                document.write("</tr>")


                document.write("<tr style='height: 12px'>")
                document.write("<td></td>")
                document.write("<td></td>")

                document.write("</tr>")

                for(var _index = 0;_index < _size;_index++){

                    document.write("<tr style='border: 1px solid gainsboro;height: 150px'>");



                    document.write("<td>");
                    document.write("<input type='checkbox' name='gonggaoid' οnclick='dataCal()'>" );

                    document.write("  <img style='vertical-align: middle 'id='img_" + data.courseDOs[_index].id + "' src='http:/************"+ data.courseDOs[_index].pictureUrl + "' width=100 height=\"100\" /> ")
                    document.write("</td>");

                    document.write("<td>");
                    document.write("<table>")

                    document.write("<tr style='border: 1px solid gainsboro'>");
                    document.write("<td style='font-size: 10px ;line-height: 25px'>"+"商品名称:"+data.courseDOs[_index].courseTitle+"</td>")
                    document.write("</tr>");

                    document.write("<tr>");
                    document.write("<td style='font-size: 10px;line-height: 25px'>"+"商品的时间:"+data.courseDOs[_index].uploadTime+"</td>")
                    document.write("</tr>");
                    document.write("<tr>");
                    document.write("<td style='font-size: 10px;line-height: 25px'>"+"价格:"+"<span name='priceid'>"+ data.courseDOs[_index].price+"</span>"+".0元"+"</td>")
                    document.write("</tr>");
                    document.write("</table>");
                    document.write("</td>");

                    document.write("<tr style='height: 10px'>")
                    document.write("<td></td>")
                    document.write("<td></td>")

                    document.write("</tr>")

                    document.write("</tr>");



//                    document.write("<tr>"+"<td>" + "<div class='content'>" + "</div>"+" </td>" +"</tr>")
//                    document.write("<td>" + "<div class='right-div'>" + "</div>"+" </td>")
//                    document.write("<img style='vertical-align: middle 'id='img_" + data.courseDOs[_index].id + "' src='"+ data.courseDOs[_index].pictureUrl + "' width='100' height=\"100\" /> " + data.courseDOs[_index].courseTitle +data.courseDOs[_index].uploadTime )
//                    $(".content").append("<img style='vertical-align: middle 'id='img_" + data.courseDOs[_index].id + "' src='"+ data.courseDOs[_index].pictureUrl + "' width='100' height=\"100\" /> "   );
//                    $(".right-div").append( data.courseDOs[_index].courseTitle+"<br/>"+ data.courseDOs[_index].uploadTime+"<br>"+ data.courseDOs[_index].price+"<p></p>");
//                    //$("#xxx").attr('src',data.courseDOs[_index].pictureUrl);
                }


                document.write("<tr style='height: 15px'>")
                document.write("<td></td>")
                document.write("<td></td> ")

                document.write("</tr>")


                document.write("<tr style='border: 1px solid gainsboro ;collapse: '2''>")
                document.write("<td></td>")


                document.write("<td style='font-size: 10px ;height: 50px'> 合计:<span style='color: dodgerblue;padding: 20px' id='Allcount' >0.0  元</span>" +"     "+
                    "<button style='width: 60px; height: 35px; border-radius: 5px; font-size: 14px; color: #fff; background-color: dodgerblue; border: 0' id='alipay'>结算</button></td>")
                document.write("</tr>");
                document.write("</table>");

                $('#alipay').on('click', function(e){
                    setTimeout("Success();",5000);
                });

            }
        });
    };
    test();
</script>


</body>
</html>

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

冉然

你的鼓励对我很重要

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值