如何在下面的代码中修复未定义的值错误

时间:2013-01-24 20:21:39

标签: jquery html

我正在检索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;   
}

2 个答案:

答案 0 :(得分:0)

更改

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

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

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

答案 1 :(得分:0)

好像你需要

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

value是未定义的变量