gpt4 book ai didi

jquery 验证不显示错误消息

转载 作者:行者123 更新时间:2023-12-01 02:54:05 24 4
gpt4 key购买 nike

我搜索过类似的问题,但没有找到乐趣。就发送函数中的逻辑而言,验证有效,但验证元素后面的范围在无效时不会显示错误消息。我什至尝试过传递 errorPlacement,但唯一有效的是如果我专门将其设置为这样

$("#msgvalid").text($("#msg").attr("data-val-required"));

相关的html是

<form id="frmSend" style="margin-top:15px">
Add Comment:
<div>
<textarea id="msg" data-val="true" data-val-required="The comment cannot be blank." placeholder="Enter comment here" style="height:50px;width:300px"></textarea>
<span id="msgvalid" class="field-validation-valid text-danger" data-valmsg-for="msg" data-valmsg-replace="true"></span>
</div>
<button type="button" onclick="send();" class="btn-default" style="margin-top:10px">Send Comment</button>
</form>
<script src="/Scripts/jquery-1.10.2.js"></script>
<script src="/Scripts/bootstrap.js"></script>
<script src="/Scripts/respond.js"></script>
<script src="/Scripts/jquery.validate.js"></script>
<script src="/Scripts/jquery.validate.unobtrusive.js"></script>

相关的javascript是

<script type="text/javascript">
function send() {
$("#frmSend").validate();
if (!$("#frmSend").valid()) { return false; }
alert("Would send");
}
</script>

最佳答案

您必须在考虑进行验证的每个输入元素上具有 name 属性...

Documentation:

The name attribute is "required" for input elements, the validation plugin doesn't work without it.

关于jquery 验证不显示错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31393797/

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