gpt4 book ai didi

jquery - 如何使用 jQuery Validator 添加错误消息

转载 作者:行者123 更新时间:2023-11-28 02:28:04 26 4
gpt4 key购买 nike

我的“联系我”表单可以根据需要进行验证,但我不知道如何显示错误消息。我试图阅读文档,但我只是不明白如何使用 errorPlacement 函数。有人可以给我一个例子,说明如何使用我得到的代码来做到这一点吗?

<fieldset>
<input placeholder="Ditt navn" name="contact_name" id="contact_name" class="contact_input" type="text" tabindex="1" required autofocus>
</fieldset>
<fieldset>
<input placeholder="Din email adresse" name="contact_mail" id="contact_mail" class="contact_input" type="email" tabindex="2" required>
</fieldset>
<fieldset>
<input placeholder="Firma navn (valgfri)" name="contact_firmname" id="contact_firmname" class="contact_input" type="text" tabindex="3">
</fieldset>


$(document).ready(function(){
$('body').on('keyup','#contact_me',function(){
$('#contact_me').validate({
rules: {
contact_name: {
required: true,
remote: location.protocol + '//' + location.host+'/ajax_contact.php'
},
contact_mail: {
required: true,
remote: location.protocol + '//' + location.host+'/ajax_contact.php'
},
contact_firmname: {
},
},
errorPlacement: function(){
return false;
},
submitHandler: function (form) {
return false;
}
});
});
});

最佳答案

如果您不知道如何做某事,请不要拘泥于文档。而是寻找一个示例,它通常清晰 1000 倍。

本文展示了一个您尝试在代码中重现的可测试示例:https://www.webcodegeeks.com/javascript/jquery/jquery-errorplacement-example/

关于jquery - 如何使用 jQuery Validator 添加错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47839909/

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