0

我正在检索一个referenceError stating: value is not defined. 我试图将一个Remove按钮设置为一个值,以便它删除与该值关联的文本输入。但我不知道要设置什么value来修复错误,因为var value=''没有用。我应该设置value什么?

下面是代码:

function stopImageUpload(success, imageID, imagefilename){

      var result = '';
      imagecounter++;

      if (success == 1){
         result = '<span class="imagemsg'+imagecounter+'">The file was uploaded successfully</span>';   
            $('.hiddenimg').eq(window.lastUploadImageIndex).append('<input type="text" name="imgid[]" id="'+imageID+'" value="' + imageID + '" />');
            $('.listImage').eq(window.lastUploadImageIndex).append('<div>' + htmlEncode(imagefilename) + '<button type="button" class="deletefileimage" data-imageID="'+imageID+'"  data-image_file_name="' + imagefilename + '" value="'+imageID+'">Remove</button><br/><hr/></div>');
         }


  var _imagecounter = imagecounter;

$('.listImage').eq(window.lastUploadImageIndex).find(".deletefileimage").on("click", function(event) {
    jQuery.ajax("deleteimage.php?imagefilename=" + $(this).attr('data-image_file_name')).done(function(data) {
        $(".imagemsg" + _imagecounter).html(data);
    });

    var buttonid = $(this).attr(value);
    $(this).parent().remove();
     $("#"+ buttonid  +"").remove();
});

      return true;   
}
4

2 回答 2

0

改变

var buttonid = $(this).attr(value);

var buttonid = $(this).attr('value');

或将值初始化为某个属性名称。

于 2013-01-24T20:25:24.767 回答
0

看来你需要

var buttonid = $(this).attr('value');

或者value是一个未定义的变量

于 2013-01-24T20:27:32.237 回答