使用 javascript 更改必填字段验证器错误消息
本文关键字:验证 错误 消息 字段 javascript 使用 | 更新日期: 2023-09-27 18:30:54
我有一个必填字段验证器,其中包含一般错误消息;使用java脚本,我想根据某些条件更改错误
我正在使用此代码
var RfvInternalNotes = document.getElementById("RfvInternalNotes");
RfvInternalNotes.innerText = "";
RfvInternalNotes.innerText = "Please enter a reason for assigning this question to a different person";
没有 JavaScript 错误,但我的自定义消息没有显示,而是显示我在必填字段验证器属性中设置的错误消息。我也试过这个
RfvInternalNotes.ErrorMessage= "Please enter a reason for assigning this question to a different person";
但没有快乐;有什么帮助吗?谢谢
我认为你可以更好地使用自定义验证器并使用它的ClientValidationFunction函数,这些函数可能以某种方式看起来像:
<asp:CustomValidator id="CustomValidator1"
ClientValidationFunction="MyClientValidationFunction" />
<script language="javascript">
function MyClientValidationFunction(sender, args){
sender.errormessage = "Validation failed";
args.IsValid = true; // false based upon your conditions...
return;
}
</script>
客户端验证函数参考
发现问题;我也在其他地方调用该函数;现在正在工作