这是我的代码:
$(document).ready(function() {
$('.submit').click(function() {
var answer_text = $("#answer_text").val();
if (answer_text === '' || undefined === $("input[name='answer[scale]']:checked").val()) {
alert('error!!');
return false;
}
else {
alert('yeah! cool baby!');
}
}
});
问题:jQuery 看不到 ||
。我不知道该怎么办。我尝试做类似的事情:
if
else if
else
或
if
else
if
else
不知道该怎么办。请帮助我,也许 OR 运算符有一些错误和错误?或者什么?
最佳答案
要知道是否没有选中任何复选框,只需使用长度,无需弄乱值:
if (answer_text === '' || $("input[name='answer[scale]']:checked").length === 0) {
//answer text is empty and no answer scale checkbox was checked
}
关于javascript - jquery表单的一些问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7317294/