gpt4 book ai didi

javascript - 显示消息而不是警报

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:25:23 25 4
gpt4 key购买 nike

我正在使用 this用于检查我的所有字段是否已填写的惊人 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;
}
});
});

我尝试使用回显消息,但没有成功。

最佳答案

您可以设计自己的弹出窗口。或者使用一些插件。

http://jquerybyexample.blogspot.com/2013/01/jquery-popup-window-tutorial-plugins.html

或者您可以在页面上创建一些元素,以显示错误消息。写一些样式,让它看起来很棒!

<div class="error-messages" style="display:none;"></div>

表单发送后,检查错误,写这个。

$(".error-messages").text("Some error").fadeIn();

或者您可以将其清空并在几秒钟后或用户获得焦点后将其隐藏。

$(".error-messages").empty().fadeOut();

关于javascript - 显示消息而不是警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18142652/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com