gpt4 book ai didi

javascript - 取消确认窗口但是

转载 作者:行者123 更新时间:2023-11-30 14:46:41 24 4
gpt4 key购买 nike

当我点击取消表单提交时((为什么?我尝试添加到“”。一切都很好。但只有当 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() 的函数中返回。参见 the documentation其中说:

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

循环,而不是表单提交!


您需要从传递给 submit() 的函数返回(或者,更好的是,捕获给该函数的第一个参数(the event object)和 call preventDefault())。

关于javascript - 取消确认窗口但是,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48804061/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com