Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery验证未停止回发_Jquery_Validation_Http Post_Event Bubbling - Fatal编程技术网

jQuery验证未停止回发

jQuery验证未停止回发,jquery,validation,http-post,event-bubbling,Jquery,Validation,Http Post,Event Bubbling,我有一个使用jQuery定义的自定义验证器,该验证器检查以确保在HTTPPost发生之前完成所需字段。我的脚本如下: <script> $(document).ready(function() { $('#ContentProperties').hide(); $('#FileSubmit').hide(); }); $(function () { $("input:file").change(function () { var fileNa

我有一个使用jQuery定义的自定义验证器,该验证器检查以确保在HTTPPost发生之前完成所需字段。我的脚本如下:

<script>
$(document).ready(function() {
    $('#ContentProperties').hide();
    $('#FileSubmit').hide();
});

$(function () {
    $("input:file").change(function () {
        var fileName = $(this).val();
        if(fileName != null)
            $('#FileSubmit').show();
            $('#ContentProperties').show();
            alert("File successfully chosen please enter required metadata below");
    });
});

$(document).ready(function () {
    $("#FileSubmit").click(function () {
        var name = document.getElementById("name").value;
        var author = document.getElementById("author").value;
        var description = document.getElementById("description").value;
        var uploadDate = document.getElementById("uploaddate").value;
        var expiryDate = document.getElementById("expirydate").value;
        var contentType = document.getElementById("contenttypeid").value;
        var alertString = "";

        if (name.length == 0) {
            alertString += "NAME: You must enter a name for your content!\n" 
        }

        if (author.length < 6) {
            alertString += "AUTHOR: You must enter at least 6 characters for author!\n"
        }

        if (description.length < 20) {
            alertString += "DESCRIPTION: You must enter a valid description of at least 20 characters !\n"
        }

        if (uploadDate.length < 8 || uploadDate.length > 10) {
            alertString += "UPLOAD DATE: Date must be entered in format 01/01/2013 or 1/1/2013\n"
        }

        if (expiryDate.length < 8 || expiryDate.length > 10) {
            alertString += "EXPIRY DATE: Date must be entered in format 01/01/2013 or 1/1/2013\n"
        }

        if (alertString.length > 0) {
            alert(alertString)
            event.cancelBubble = true;
            event.returnValue = false;
            event.preventDefault();
            event.stopPropagation();
            return false;
        }
    });
});

您尚未定义
事件

$("#FileSubmit").click(function (event) {
虽然我通常使用
e
作为惯例:

$("#FileSubmit").click(function (e) {
    e.preventDefault();
});

旁注:我会将此更改为将处理程序附加到表单提交,而不是单击提交按钮。您可以通过按enter键提交表单,它将跳过您的单击处理程序。

您在函数调用中没有引用“事件”:

$("#FileSubmit").click(function (event) { ....

非常感谢,非常感谢。是否将附加到submit的操作完成$(“#FileSubmit”).onsubmit?是的,我认为确切的语法应该是
$('#MyForm').submit(函数(e){})
$('#MyForm')。关于('submit',函数(e){})请注意,您必须将事件附加到表单,而不是按钮。
$("#FileSubmit").click(function (event) { ....