<form action="index.php" method="post" enctype="multipart/form-data"  onsubmit="return check_form(this)">
<input type="file" id="file" />
<input type="submit" value="确定" />
</form><script type="text/javascript">
function check_form(obj){
var file = document.getElementById('file');
var value = file.value;
var type = value.substr(a.lastIndexOf('.') + 1);
if(type != 'zip'){
alert('不是zip文件');
return false;
}
return true;
}

</script>

解决方案 »

  1.   

    上面写错了,var type = value.substr(a.lastIndexOf('.') + 1);改成var type = value.substr(type.lastIndexOf('.') + 1);
      

  2.   

    <form action="index.php" method="post" enctype="multipart/form-data"  onsubmit="return check_form()">
        <input type="file" id="file" />
        <input type="submit" value="确定" />
    </form>
    <script type="text/javascript">
    function check_form(){
    var file = document.getElementById('file').value;
    var reg=/\.zip$/i;
    if(!reg.test(file)){
    alert("注:请上传zip压缩包!");
    return false;
    }
    }
    </script>