jQuery validate().element() 不直接显示错误
我正在使用 jQuery UI 选项卡控件来实现一个简单的向导。为了进行验证,我使用 jQuery 验证。当按“下一步”按钮移至向导的下一个选项卡时,我会验证当前选项卡上的所有内容:
$('.forward').click(function () {
var valid = true;
$(this).closest("div").find("input").each(function () {
valid = valid && $("#form").validate().element(this);
});
// Code to select next tab if valid
});
这有效 - 我在 valid
中获得了正确的值。但是,如果出现任何问题,错误消息不会立即显示。我必须单击其他地方才能使下一个按钮在错误消息出现之前失去焦点。
如何让错误消息在运行 validate().element(this)
后立即出现?
I'm using a jQuery UI tab control to implement a simple wizard. For validation I'm using jQuery validation. When pressing the "next" button to move on to the next tab of the wizard, I validate everything on the current tab:
$('.forward').click(function () {
var valid = true;
$(this).closest("div").find("input").each(function () {
valid = valid && $("#form").validate().element(this);
});
// Code to select next tab if valid
});
This works - I get the correct value in valid
. However, if anything is wrong, the error message doesn't show up immediately. I have to click somewhere else to make the next button lose focus before the error message appears.
How can I make the error messages appear immediately after running validate().element(this)
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的方法的行为类似于模糊或 keyup 的验证,但返回结果。
这里没有模糊或按键。
尝试
Your method behaves as validation on blur or keyup, but returns the result.
You don't have blur or keyup here.
try