zoukankan      html  css  js  c++  java
  • jquery+php实现节点添加和异步删除

        <div class="formbody">
            <div class="formtitle"><span>商品相册</span></div>
            <li style="border: 1px solid grey;margin-bottom: 20px;">
                {volist name="data" id="vol"}
                <span><img src="{$vol.pics_mid|ltrim='.'}" width="178"><a href="javascript:;" class="remove" data="{$vol.pics_id}">[-]</a>&emsp;</span>
                {/volist}
            </li>
            <form action="" method="post" enctype="multipart/form-data">
                <ul class="forminfo">
                    <li>
                        <label>商品图片[<a href="javascript:;" class="add">+</a>]</label>
                        <input name="goods_pic[]" type="file" />
                    </li>
                    <li>
                        <label>&nbsp;</label>
                        <input name="" id="btnSubmit" type="button" class="btn" value="确认保存" />
                    </li>
                </ul>
            </form>
        </div>
    
    <script type="text/javascript">
    $(function(){
        //表单提交
        $('#btnSubmit').on('click',function(){
            $('form').submit();
        })
        //点击添加取消
        $('.add').click(function(){
            var li="<li><label>商品图片[<a href='javascript:;' class='del'>-</a>]</label><input name='goods_pic[]' type='file' /></li>";
            $(this).parent().parent().after(li);
        });
        $('.del').live('click',function(){
            $(this).parent().parent().remove();
        });
        //异步删除
        $('.remove').click(function(){
            var pics_id=$(this).attr('data');
            var _this=$(this);
            $.ajax({ 
                type: "get", 
                data:  "pics_id="+pics_id, 
                url: "{:url('photos_del')}", 
                dataType:"json",
                success: function(data) { 
                console.log(data); 
                    if(data==1){
                        _this.parent().remove();
                    }else{
                        alert('删除失败');
                    }
                }, 
            });
        });
        
    });
    </script>
    <?php
    
    
        public function photos_del($pics_id){
            $Goodspics=model('Goodspics');
            $data=$Goodspics->find($pics_id);
            $ab_url=ROOT_PATH . 'public';
            @unlink($ab_url. $data['pics_big']);
            @unlink($ab_url. $data['pics_mid']);
            @unlink($ab_url. $data['pics_sma']);
            $result=$Goodspics->where('pics_id',$pics_id)->delete();
            return  $result ? 1 : 0; 
        }

     

     参考地址  https://www.cnblogs.com/keyi/p/5817728.html

  • 相关阅读:
    VS.net 2005快捷键一览表
    POJ 1141 Brackets Sequence
    POJ 3264 Balanced Lineup RMQ问题的ST解法
    Hdu 4267 A Simple Problem with Integers
    hdu 4009 Transfer water
    HDU 4288 Coder
    POJ 1679 The Unique MST
    hdu 4291 A Short problem
    hdu 1175 连连看(DFS)
    POJ 3164 Command Network
  • 原文地址:https://www.cnblogs.com/mengor/p/8315891.html
Copyright © 2011-2022 走看看