1.使用onsubmit方法
<form name="Form" action="t" method="post" οnsubmit="return check();"> <input class="btn btn-default" id="excel_file" type="file" name="filename" accept="xls"/> <input id="excel_button" type="submit" value="导入Excel"/> </form> //onsubmit事件无法触发,使用绑定button点击事件取代 function check() { alert("check"); var excel_file = $("#excel_file").val(); if (excel_file == "" || excel_file.length == 0) { alert("请选择文件路径。"); return false; } else { return true; } } 2.使用button事件绑定 $("#excel_button").on('click', function() { var excel_file = $("#excel_file").val(); if (excel_file == "" || excel_file.length == 0) { alert("请选择文件路径!"); return false; } else { return true; } });转载于:https://www.cnblogs.com/bhlsheji/p/5325666.html
相关资源:数据结构—成绩单生成器