This article shows the method of judging file upload type in JavaScript, which is a very common technique. The specific implementation method is as follows:
A function is used when uploading files, using the input tag of the html element:
<input id="imageFile" name="imageFile1" accept="image/jpg,image/jpeg,image/png,image/bmp,image/gif" type="file" onchange="imageSubmit(this,0);"/>
The onchange event is triggered immediately after selecting the image, but repeatedly selecting the same image will not trigger the onchang event. The solution is as follows:
function imageSubmit(obj, imageType) { if (imageType == "0") { //Related processing code... //Solve that uploading the same image does not trigger the onchange event var nf = obj.cloneNode(true); nf.value=''; obj.parentNode.replaceChild(nf, obj); }}The cloneNode() method is used to create an identical copy of the call to this node. The parameter true means performing deep replication, that is, copying the node and the entire child node tree. When the parameter is false, performing shallow replication, that is, only copying the node itself. The replica returned after copy belongs to the document, but does not specify a parent node for it. Therefore, this node copy becomes an "orphan" unless it is added to the document via appendChild(), insertBefore() or replaceChild().
I hope that the description in this article will be helpful to everyone using JavaScript for web programming.