如何从div中删除隐藏的输入

时间:2013-01-24 02:02:09

标签: jquery html

我想在“删除”按钮或删除函数被调用时删除隐藏的输入,但问题是,如果下面的代码没有删除输入,我怎样才能获得要删除的正确输入取决于删除的文件名?下面是删除正确文件名但不删除隐藏输入的代码(对于测试我将其更改为文本输入):

  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="hidden" 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 + '">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);
        });

        $(this).parent().remove();
        $(".hiddenimg").parent().remove();
    });

          return true;   
    }

以下是文件输入表格:

var $fileImage = $("<form action='imageupload.php' method='post' enctype='multipart/form-data' target='upload_target_image' onsubmit='return imageClickHandler(this);' class='imageuploadform' >" + 
"<p class='imagef1_upload_form'><label>" + 
"Image File: <input name='fileImage' type='file' class='fileImage' /></label><br/><br/><label class='imagelbl'>" + 
"<input type='submit' name='submitImageBtn' class='sbtnimage' value='Upload' /></label>" + 
"<input type='hidden' class='numimage' name='numimage' value='" + GetFormImageCount() + "' />" +</p>
"</p><p class='imagemsg'></p><p class='listImage'></p>" +
"<iframe class='upload_target_image' name='upload_target_image' src='/' style='width:0px;height:0px;border:0px;solid;#fff;'></iframe></form>");     

隐藏的输入被放置在另一种形式的div中,并且它是另一种形式的原因是因为上面的表单将嵌套到下面的表单中,如果我在上面的表单中包含隐藏的输入,那么我将有问题使用$ _POST以嵌套形式发布隐藏输入中的值:

<form id="QandA" action="" method="post">
<div class='hiddenimg'></div>
</form>

0 个答案:

没有答案