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.     });  


     
  • 相关阅读:
    ZOJ 1002 Fire Net
    Uva 12889 One-Two-Three
    URAL 1881 Long problem statement
    URAL 1880 Psych Up's Eigenvalues
    URAL 1877 Bicycle Codes
    URAL 1876 Centipede's Morning
    URAL 1873. GOV Chronicles
    Uva 839 Not so Mobile
    Uva 679 Dropping Balls
    An ac a day,keep wa away
  • 原文地址:https://www.cnblogs.com/mafeng/p/7681465.html
Copyright © 2011-2022 走看看