$('#delete').click(function (e) {
e.preventDefault();
var result = true;
if($('.checkbox:checked').length < 1) {
$.notifyBar({
cls: "error",
html: 'At least 1 checkbox must be checked.',
delay: 5000
});
result = false;
}
return result;
});
问题是如果一切顺利的话按钮不会提交表单 有什么不妥吗?
最佳答案
对 e.preventDefault()
的调用阻止了提交表单的按钮的默认操作。您只需要在不希望提交发生时调用它。
$('#delete').click( function(e) {
if($('.checkbox:checked').length<1){
$.notifyBar({
cls: "error",
html: 'At least 1 checkbox must be checked.',
delay: 5000
});
// Invalid, stop the submit
e.preventDefault();
}
})
关于javascript - 点击功能有问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9083439/