form表单提交之前判断


1.使用onsubmit方法

 

  1. <form name="Form" action="t" method="post" onsubmit="return check();">  
  2. <input class="btn btn-default" id="excel_file" type="file" name="filename"  accept="xls"/>  
  3. <input  id="excel_button" type="submit" value="导入Excel"/>  
  4. </form>  

  1. //onsubmit事件无法触发,使用绑定按钮点击事件代替  
  2.    function check() {  
  3.     alert("check");  
  4.     var excel_file = $("#excel_file").val();  
  5.     if (excel_file == "" || excel_file.length == 0) {  
  6.         alert("请选择文件路径!");  
  7.         return false;  
  8.     } else {  
  9.            return true;  
  10.        }  
  11. }  

2.使用按钮事件绑定

 

  1. $("#excel_button").on('click', function() {  
  2.         var excel_file = $("#excel_file").val();  
  3.         if (excel_file == "" || excel_file.length == 0) {  
  4.             alert("请选择文件路径!");  
  5.             return false;  
  6.         } else {  
  7.             return true;  
  8.         }  
  9.     });  


 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM