<a>的javascript+jquery编程实例之删除(定位节点与事件绑定)

相关jquery方法 parent(), remove()

//上传图片 article_create.js  article_edit.js
function uploadAttachment() {
    /*jQuery-File-Upload*/
    var url = '/Common/UploadAttachment';
    $('#fileupload').fileupload({
        url: url,
        dataType: 'json',
        done: function (e, data) {
            if (data.result.result === true) {
                if (data.result.files.length > 0) {
                    var imgTpl = genrateTmp(image_index);
                    $("div.media").append(imgTpl);
                    var curIndex = $(imgTpl).attr("data-index");
                    var file = data.result.files[0];
                    $("#preview_img_" + curIndex)[0].src = file.url;
                    $('#save_name_' + curIndex).val(file.saveName);
                    $('#files_' + curIndex).text(file.name);
                    //$("#beforeUpload").removeClass('disabled');
                }
            }
            else {
                alert(data.result.Message);
            }
        }
    });
}

function genrateTmp(dataIndex) {
    var tpl = '<div class="media-body" data-index="{i}">'
        + '<input name = "save_name_{i}" type = "hidden" id = "save_name_{i}" value = "" data-model="article.ImgFileList" />'
        + '<div id="files_{i}" class="files"></div><a onclick="DelImage(this)">删除</a>'
        + '<a class="pull-left thumbnail">'
        + '<img id="preview_img_{i}" class="media-object" src="" onload="DrawImage(200, 200, this)">'
        + '</a>'
        + '</div >';
    tpl = tpl.replace(/{i}/g, dataIndex);
    ++image_index;
    return tpl;
}

function DelImage(obj)
{
    $(obj).parent().remove();
}

 

posted @ 2019-11-14 16:35  轴轴  阅读(234)  评论(0编辑  收藏  举报