我有一個表,我遍歷每一行。 如果行背景顏色爲綠色,並且其各自的複選框以classbox作爲linebox未被選中,我應該在點擊提交時顯示錯誤消息。 但返回false不起作用,表單正在提交。儘管消息正在顯示。 我該如何解決這個問題? 以下是代碼。jQuery返回false不工作
jQuery(document).on('click', '#add-All-button', function() {
$(".rowb").each(function() {
if($(this).css("background-color") == "rgb(71, 163, 71)") {
var ischk = 0;
var row = $(this);
if (row.find('input[class="linebox"]').is(':checked')) {
ischk++;
}
if(ischk==0) {
alert('Every green colored row should have one of the checkboxes checked.');
return false;
}
}
});
});
謝謝Shane!上述代碼在條件爲真時不起作用。它總是阻止表單提交。 – Viral
你可以使用event.preventDefault()來停止表單提交請參閱上面的編輯 – ShaneQful
謝謝謝恩......它解決了這個問題。非常感謝。 – Viral