How to remove the uploaded image in any box?

前端 未结 4 730
孤城傲影
孤城傲影 2021-01-27 09:42

My code is very long. I can not show you all here. I just show the javascript code only

My javascript like this :



        
4条回答
  •  有刺的猬
    2021-01-27 10:33

    Here's my answer: http://phpfiddle.org/main/code/0h1g-mvus

    I just shift the images instead. You might need to do some changes to pass values or w/e.

    let current = 0;
     for(let i = 0; i < 5; i++) {   
        $('#thumbnail-view-delete-'+i).click(function(){
            current -= 1;
            $('input[name="photo-'+i+'"]').val('');
            document.getElementById("thumbnail-view-li-"+current).style.display = "none";
            document.getElementById("thumbnail-upload-li-"+current).style.display = "";
            document.getElementById("thumbnail-upload-li-"+(current+1)).style.display = "none";
            document.getElementById("thumbnail-slot-li-"+(current+1)).style.display = "";
            shift_image(i);
        });
    }
    
    function shift_image(start)
    {
        let finish = 4;
        for (; start < finish - 1; start++)
        {
            let next = $('#thumbnail-view-'+(start+1)).attr('src');
            $('#thumbnail-view-'+start).attr('src', next);
        }
    }
    

提交回复
热议问题