zoukankan      html  css  js  c++  java
  • 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.     });  


     
  • 相关阅读:
    Java实现约瑟夫环问题
    Java实现约瑟夫环问题
    mysql远程表链接
    linux下mysql定时备份
    深入浅出RPC——浅出篇(转载)
    深入浅出RPC——深入篇(转载)
    Qt在Windows上的调试器安装与配置
    VS2015 ASP.NET5 Web项目
    jquery validate remote验证唯一性
    jQuery UI框架
  • 原文地址:https://www.cnblogs.com/mafeng/p/7681465.html
Copyright © 2011-2022 走看看