English 中文(简体)
如何清除档案输入
原标题:How to clear a file input

如果你仔细研究这一守则,就会为每个附在的行文提供文件投入。 现在,每个档案材料都有一个“Clear文档”纽州,在那里,它可以清除档案材料中的任何内容。 问题是,它没有在档案材料中清除任何东西。 为什么如此?

http://www.ohchr.org。

var sourceImageForm; 

function insertQuestion(form) {   
    var $tbody = $( #qandatbl > tbody ); 
    var $tr = $("<tr class= optionAndAnswer  align= center ></tr>");
    var $image = $("<td class= image ></td>"); 

    var $fileImage = $("<form action= imageupload.php  method= post  enctype= multipart/form-data  target= upload_target  onsubmit= startImageUpload(this);  class= imageuploadform  >" + 
        "<p class= imagef1_upload_process  align= center >Loading...<br/><img src= Images/loader.gif  /><br/></p><p class= imagef1_upload_form  align= center ><br/><label>" + 
        "Image File: <input name= fileImage  type= file  class= fileImage  /></label><br/><label class= imagelbl >" + 
        "(jpg, jpeg, pjpeg, gif, png, tif)</label><br/><br/><label>" + 
        "<input type= submit  name= submitBtn  class= sbtn  value= Upload  /></label>" + 
        "<label><input type= button  name= imageClear  class= imageClear  value= Clear File /></label>" +
        "</p> <iframe class= upload_target  name= upload_target  src= #  style= wclassth:0;height:0;border:0px;solclass #fff; ></iframe></form>");      

    $image.append($fileImage);
    $tr.append($image);  
    $tbody.append($tr); 

    $(".imageClear").click(function(event){
        event.preventDefault();
        $(this).parent().find(".fileImage").replaceWith("<input type= file  class= fileImage  name= fileImage  />");
    });

}

function startImageUpload(imageuploadform){
    $(imageuploadform).find( .imagef1_upload_process ).css( visibility , visible );
    $(imageuploadform).find( .imagef1_upload_form ).css( visibility , hidden );
    sourceImageForm = imageuploadform;
    return true;
}

function stopImageUpload(success){
    var result =   ;
    if (success == 1) {
        result =  <span class="msg">The file was uploaded successfully!</span><br/><br/> ;
    } else {
        result =  <span class="emsg">There was an error during file upload!</span><br/><br/> ;
    }
    $(sourceImageForm).find( .imagef1_upload_process ).css( visibility , hidden );
    $(sourceImageForm).find( .imagef1_upload_form ).html(result +  <label>Image File: <input name="fileImage" type="file"/></label><br/><label>(jpg, jpeg, pjpeg, gif, png, tif)</label><br/><br/><label><input type="submit" name="submitBtn" class="sbtn" value="Upload" /></label><label><input type="button" name="imageClear" class="imageClear" value="Clear File"/></label> );
    $(sourceImageForm).find( .imagef1_upload_form ).css( visibility , visible );     
    return true;   
}
问题回答

你的一般战略似乎是正确的,即用另一个投入要素取代“明确”一类文件。 我不知道为什么不工作,这里是一份简明的POJS版本,它确实工作:

<form>
  <input type="file" name="fileName">
  <input type="button" onclick="clearFileName(this);" value="Clear file input">
</form>

<script type="text/javascript">

function clearFileName(el) {
  var input = el.form.fileName;
  input.parentNode.replaceChild(input.cloneNode(false), input);
}

</script>




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签