checkbox 选中和取消选中

 <div class="tab1-zhong">
             
                        <div class="shop_all">
                            <div class="shop_all_a" style="display:block;">
                                <div class="f-j-sb b-b-1 add-yue">
                                    
                                    <div class="f-s-14 f-c-hui m-l-20" style="width:30px;text-align:left">
                                        <input type="checkbox" id="CheckAll" />
                                    </div>
                                    
                                    <div class="f-s-14 f-c-hui" style="width:258px;text-align:left">投稿名称</div>
                                    
                                    <div class="f-s-14 f-c-hui" style="margin-right: 100px;" style="width:205px;text-align:left">投稿时间</div>
                                    <div class="f-s-14 f-c-hui m-r-20" style="width:205px;text-align:center">操作</div>
                                </div>
                         
                                <?php $min_price = dr_collect_info($_GET['id'])[0]['price_min'];?>
                                <?php $max_price = dr_collect_info($_GET['id'])[0]['price_max'];?>
                               
                                {list action=module module=contribute zhenggaoid=$get.id LIKE_title=%$get.kw% order=inputtime_desc page=1 pagesize=8 urlrule='index.php?s=member&c=invite&m=my_get_list&id=$get.id&page=[page]'}
                                
                                <div class="f-j-sb b-b-1 add-yue ">
                         
                                    {if $t.tgzt == 1}
                                    <div class="f-s-14 f-c-hui m-l-20" style="width:30px;text-align:left">
                                        <input type="checkbox" class="checkbox" name="checkbox" value="{$t.id}"/>
                                    </div>
                                    {else}
                                    <div class="f-s-14 f-c-hui m-l-20" style="width:30px;text-align:left">
                                        <input type="checkbox" class="checkbox" name="checkbox" value="{$t.id}"  disabled="disabled"/>
                                    </div>
                                    {/if}
                                    <div class="f-s-14 f-c-hui" style="width:208px;text-align:left">
                                        <a href="/index.php?s=member&c=contribute&m=my_get_detail&id={$t.id}">{$t.title}</a>
                                    </div>
                                
                                    <div class="f-s-14 f-c-hui" style="width:205px;text-align:left">{$t.inputtime}</div>
                                     <!--<p style="    margin-top: 15px;">{$min_price}</p>--<p style="    margin-top: 15px;">{$max_price}</p>-->
                                    <div class="f-s-14 f-c-hui m-r-20 d-p" >
                                   
                                        <p class="f-s-14 f-c-hui m-r-20">
                                        </p>
                                        {if $t.tgzt == 1}
                                        <div class="bianji" onclick="_submit({$t.id},'agree')" style="cursor:pointer">
                                            <img src="/statics/invite/images/bianji.png">
                                            <p>约稿</p>
                                        </div>
                                        <div class="bianji" onclick="_submit({$t.id},'forbid')" style="cursor:pointer">
                                            <img src="/statics/invite/images/shanchu.png">
                                            <p>淘汰</p>
                                        </div>
                                        {else if $t.tgzt == 2}
                                            <p class="f-s14 f-c-hui "> 已拒绝</p>
                                        {else if $t.tgzt == 3}
                                            <p class="f-s14 f-c-hui ">已约稿,已完成</p>
                                        {/if}
                                       
                                        <p></p>
                                    </div>
                                </div>
                                {/list}
                                
                                <div class="f-j-sb" style="margin-top: 20px;">
                                    <div class="f-s-14 f-c-hui m-l-20" style="width:200px;text-align:left">数量总计:<span id="total_num"></span></div>
                                    <div class="f-s-14 f-c-hui m-l-20" style="width:205px;text-align:left">金额总计:<span id="total_money"></span></div>
                                    <div class="bianji" onclick="payment()" style="cursor:pointer;margin-right:37px"><p style="margin: 0 0 0px;">去结算</p></div>
                                </div>
                                
                                <ul class="pagination">
                                {$pages}
                                </ul>
                                
                                <br>

                            </div>
  
                        </div>
                        
                    </div>
<script>
    $(function(){
        
        $("#CheckAll").click(function(){
            if(this.checked){//如果自己被选中
                $("input[name=checkbox]:not(:disabled)").prop("checked", "true");
                var num = $("input[name='checkbox']:checked").length;
                $('#total_num').text(num);
                var price = {$max_price};
                $('#total_money').text(num*price);
                
            }
            else{
                $("input[name='checkbox']").each(function(){
                    this.checked=false;
                });
                $('#total_num').text('');
                $('#total_money').text('');
            }
        });
        
        $(".checkbox").click(function(){
           
            var num = $("input[name='checkbox']:checked").length;
            $('#total_num').text(num);
            var price = {$max_price};
            $('#total_money').text(num*price);
            
        });

    });
    
    function payment(){
        
        var ids = new Array();
        $('input[name="checkbox"]:checked').each(function(){
                ids.push($(this).val());
        }); 
        
        var cid = {$get.id};
        if(ids.length<1){
            layer.msg('您还没有勾选');
            return false;
        }
        
        $.ajax({
            url:'/index.php?s=member&c=contribute&m=payment',
            data:{ids:ids,cid:cid},
            dataType:'json',
            type:'post',
            success:function(res){
                layer.closeAll();
                if(res.code == 1){
                    layer.msg(res.msg);
                    setTimeout(function(){
                        window.location.reload()
                    },2000)
                }else{
                    layer.msg(res.msg)
                }
            }
        })
    }
    
</script>

 

checkbox 选中和取消选中

发表评论

电子邮件地址不会被公开。 必填项已用*标注

滚动到顶部