<script>
function check(){
var userfile=document.all.userfile.value
var str
if(userfile==""){
alert('对不起,必须用浏览才可上传资料!')
}
str=userfile.lastIndexOf(".")
str=substring(str,userfile.length)
if(str != ".rar"){
alert('对不起,不支持此格式!')
}}
<script>

解决方案 »

  1.   

    (1)只能够用“浏览”来选择文件,不能够自己输入文件的路径 //自己写也是没有有用的上传不上去
    (2)只能上传.rar文件,其他的不可以选择或者可以过滤  //屏蔽了脚本就木有用的,还是要在服务器端写验证的,如果是在选择的时候就这样弄的话是不可能的事情不过如果你做个activex一些ok了
      

  2.   

    改了一下!!
    在onsubmit="return check()" 调用
    function check(){
    var userfile=document.all.userfile.value
    var str
    str=userfile.lastIndexOf(".")
    str=userfile.substring(str,userfile.length)
    if(str == ".rar"){
    return true
    }else
    alert("不支持,此格式")
    return false
    }