input 上传文件的判断

<html>
    <head>
        <meta charset='utf-8'>
         <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
         <script type="text/javascript"  src="http://mat1.gtimg.com/libs/jquery2/2.2.0/jquery.js"></script>
    <body>
        <form action="upload.html" method="post" enctype="multipart/form-data" accept-charset="utf-8">
            <input id="file" type="file" name="选择文件"><br/>
            <input  id="fileUpload" type="submit" value="提交">
        </form>
        <script type="text/javascript">
               $("#fileUpload").click(function(){
                      
                      if($("input[type='file']").val()==""){
                      alert("请选择文件后提交");
                      return false;
                   }else{
                         return true;
                   }
               })
               




        </script>

    </body>
</html>

空文件就不要让提交

上一篇:后端解决跨域问题


下一篇:解决跨域问题代码