Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/372.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
Javascript jQuery表单验证只在一次发布时有效_Javascript_Jquery_Forms_Checkbox - Fatal编程技术网

Javascript jQuery表单验证只在一次发布时有效

Javascript jQuery表单验证只在一次发布时有效,javascript,jquery,forms,checkbox,Javascript,Jquery,Forms,Checkbox,用户必须至少选择一个复选框选项。如果有效>提交表单。只工作一次。如果用户选中并取消选中该框,然后再次提交,则表单将提交为空 $('#submit-button').on('click', function() { $('input:checkbox').each(function() { if (!$(this).is(":checked")) { $('#submit-error').html('Plase select at least one

用户必须至少选择一个复选框选项。如果有效>提交表单。只工作一次。如果用户选中并取消选中该框,然后再次提交,则表单将提交为空

$('#submit-button').on('click', function() {
    $('input:checkbox').each(function() {
        if (!$(this).is(":checked")) {
            $('#submit-error').html('Plase select at least one option!');
            return false;
        } else {
            $('#my-form').submit();
        }
    });
});

编辑:此表单位于模式窗口中

谢谢您的建议。它仍然不起作用。我应该补充一点,如果这有什么不同的话,这个表单是在一个模态窗口中。事实上,我确实有一个输入错误,你的代码正在工作!非常感谢。
$('#submit-button').on('click', function() {
    if(!$('input[type="checkbox"]:checked').length)
    {
        $('#submit-error').html('Plase select at least one option!');
        return false;
    }
    else 
       $('#my-form').submit();
});