【发布时间】:2011-11-30 13:47:47
【问题描述】:
我有一个提交表单的按钮的功能。此函数检查是否选中了 5 个复选框 #co1,#co2,#co3,#div1,#cc1。
然后它还会检查 tcaccept select 是否设置为 1。 如果是,则表单提交,否则会弹出警报。
这是我目前的代码:
$('#submit2pd').click(function(event) {
var $finishBoxes = $('#co1,#co2,#co3,#div1,#cc1');
if (!($finishBoxes.length == $finishBoxes.filter(':checked').length && $('#tcaccept').val() == '1' )) {
alert('Please complete the Induction Checklist confirming that you have read and understood the Colleges main policies and procedures, agreeing to comply with these in line with the terms of your contract with the College');
return false;
}
// otherwise the form is submitted
window.location.href = "submit2pd.php";
});
所有工作都非常出色,但我想添加到这一行,因为我需要另一个选项。但这需要是一个 if 语句。
if (!($finishBoxes.length == $finishBoxes.filter(':checked').length && $('#tcaccept').val() == '1' && THE IF STATEMENT))
这是我需要合并到上面的 if 语句中的内容。
if ($("#ctl").val() == "1") {
$('#ctlapp') must not be blank
}
else if ($("#ctl").val() == "0") {
$('#ctlapp') can be blank
}
任何帮助将不胜感激。
【问题讨论】:
-
为什么不把第二个 if else 块放在第一个 if 块中,而不是尝试放在 if 语句中?
-
请重新标记 - 您的问题是理解基本的编程概念、值得注意的布尔值和运算符。 jQuery在这里是无辜的!
-
$("#ctl")可以有除"0"和"1"以外的值吗?如果是这样,应该怎么办?
标签: javascript jquery forms validation