Home >Web Front-end >JS Tutorial >js determine file type and control form submission sample code_javascript skills

js determine file type and control form submission sample code_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:15:131068browse

The following code implements control form submission

Copy code The code is as follows:

function shangchuan() {

var filepath = document.getElementById("file").value;
alert(filepath);
if(filepath==""){
alert("Please choose to upload file! ");
document.getElementById("file").disabled=true;

}
var extname=filepath.substr(filepath.length-3, filepath.length);
alert("extname::" extname);
//var extname = filepath.substring(filepath.lastIndexOf(".") 1,filepath.length);
// extname = extname.toLowerCase ();//Handling case
if(extname!= "bmp" && extname!= "jpg" && extname!= "gif"){
alert("Only bmp, jpg, gif can be uploaded Format pictures! ");

document.getElementById("file").disabled=true;
}
else{
document.getElementById("file").disabled=false ;
}

}

Copy code The code is as follows:


< ;/td>


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn