• 微信号:Zh-y9213
您当前的位置:爱资源分享网 > > 知识大全 > 建站知识

JS实现Form表单提交之前判断

栏目:建站知识时间:2022-11-30 09:41阅读数:152人阅读

JS实现Form表单提交之前判断

前言:

JS实现Form表单提交之前判断,如果对你有帮助就看看吧。

正文:

1.使用onsubmit方法

<form name="Form" action="t" method="post" >  

<input class="btn btn-default" id="excel_file" type="file" name="filename"  accept="xls"/>  

<input  id="excel_button" type="submit" value="导入Excel"/>  

</form>  

onsubmit事件无法触发,使用绑定按钮点击事件代替  :

   function check() {  

    alert("check");  

    var excel_file = $("#excel_file").val();  

    if (excel_file == "" || excel_file.length == 0) {  

        alert("请选择文件路径!");  

        return false;  

    } else {  

           return true;  

       }  

}

2.使用按钮事件绑定

$("#excel_button").on('click', function() {  

        var excel_file = $("#excel_file").val();  

        if (excel_file == "" || excel_file.length == 0) {  

            alert("请选择文件路径!");  

            return false;  

        } else {  

            return true;  

        }  

    });

资源均来自第三方,谨慎下载,前往第三方网站下载 解压密码:www.xkwo.com 解压密码:www.xkwo.com 解压密码:www.xkwo.com 解压密码:www.xkwo.com 解压密码:www.xkwo.com 解压密码:www.xkwo.com 解压密码:www.xkwo.com 解压密码:www.xkwo.com

本站所有文章、数据、图片均来自互联网,一切版权均归源网站或源作者所有。

如果侵犯了你的权益请来信告知我们删除。邮箱:737597453@qq.com