取消确认windows 但是

Cancel confirm windows but

当我点击取消表单提交时(( 为什么? 我尝试添加到“”。一切都很好。但只有当 tr backgorund 颜色为黄色时,我才需要确认。这样它就不会取消提交...

$('#cart_form').submit(function() {
    $("tr").each(function(indx, element)
    {

        if (element.style.backgroundColor=="rgb(255, 255, 179)"){
            var c = confirm("Are u sure?");
            return c;
        }
    });
});

您正在从传递给 each() 的函数中 returning。见 the documentation 说:

You can stop the loop from within the callback function by returning false.

循环,不是表单提交!


您需要从传递给 submit() 的函数中 return (或者,更好的是,捕获提供给该函数的第一个参数(the event object) and call preventDefault() 在上面)。