Erw*_*ren 3 javascript forms validation alert
我正在使用这个神奇的javascript检查我的所有字段是否都已填写,但我想在页面上显示一条消息,而不是一个警报框
$(document).ready(function() {
$('form').submit(function() {
var incomplete = $('form :input').filter(function() {
return $(this).val() == '';
});
//if incomplete contains any elements, the form has not been filled
if(incomplete.length) {
alert('Vul alle velden in en probeer het nog eens');
//to prevent submission of the form
return false;
}
});
});
Run Code Online (Sandbox Code Playgroud)
我尝试播放回显消息,但没有成功
您可以设置自己的弹出窗口的样式。或使用一些插件。
http://jquerybyexample.blogspot.com/2013/01/jquery-popup-window-tutorial-plugins.html
或者,您可以在页面上创建一些元素,以显示错误消息。写一些样式,使其看起来很棒!
<div class="error-messages" style="display:none;"></div>
Run Code Online (Sandbox Code Playgroud)
表单发送完并检查错误后,编写此代码。
$(".error-messages").text("Some error").fadeIn();
Run Code Online (Sandbox Code Playgroud)
或者,您可以在几秒钟后或在用户聚焦之后将其清空并隐藏。
$(".error-messages").empty().fadeOut();
Run Code Online (Sandbox Code Playgroud)