首页 > 其他 > 详细

form表单提交之前推断

时间:2016-03-27 15:26:17      阅读:144      评论:0      收藏:0      [点我收藏+]

1.使用onsubmit方法


<form name="Form" action="t" method="post" onsubmit="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;
        }
    });


form表单提交之前推断

原文:http://www.cnblogs.com/bhlsheji/p/5325666.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!