<body>
<input type="file" id="file"/><span></span>
</body>
</html>
<script type="text/javascript">
var file = document.getElementById("file");
file.onchange = function(){
var path = file.value;
var PATH = path.substr(path.lastIndexOf(".")).toUpperCase();//toUpperCase()字符全部转为大写,.jpg = .JPG,这样做能少做判断
if(PATH ==".PNG" || PATH == ".JPG"){
this.nextSibling.innerHTML = "格式正确";
}else{
this.nextSibling.innerHTML = "格式错误";
}
}
</script>
<input type="file" id="file"/><span></span>
</body>
</html>
<script type="text/javascript">
var file = document.getElementById("file");
file.onchange = function(){
var path = file.value;
var PATH = path.substr(path.lastIndexOf(".")).toUpperCase();//toUpperCase()字符全部转为大写,.jpg = .JPG,这样做能少做判断
if(PATH ==".PNG" || PATH == ".JPG"){
this.nextSibling.innerHTML = "格式正确";
}else{
this.nextSibling.innerHTML = "格式错误";
}
}
</script>