gpt4 book ai didi

javascript - 自定义验证器未触发

转载 作者:行者123 更新时间:2023-12-03 07:08:12 24 4
gpt4 key购买 nike

我有一个名为gv1的 GridView 。里面有checkbox,至少要勾选1个checkbox才能处理。我对其进行了自定义验证,但它不起作用。请看下面,

自定义验证器

<asp:CustomValidator runat="server" ID="vldItemCus"
ClientValidationFunction="ValidateSelection"
Display="None" ErrorMessage="Select atleast one item for update" ValidationGroup="Update"></asp:CustomValidator>

验证摘要

<asp:ValidationSummary ID="vldSummary" runat="server" ShowMessageBox="True" ShowSummary="False" ValidationGroup="Update"></asp:ValidationSummary>

Javascript函数

function ValidateSelection(source, args) {
var found = 0;
$('#gv1 input[type=checkbox]').each(function () {
if (this.checked) {
found = 1;
return false;
}
});
if (found == 1) {
args.IsValid = true;
}
else {
args.IsValid = false;
}
return;
}

最佳答案

更改功能如下,

function ValidateSelection(source, args) {
var found = 0;
$('#<%= gv1.ClientID %> input[type=checkbox]').each(function () {
if (this.checked) {
found = 1;
return false;
}
});
if (found == 1) {
args.IsValid = true;
}
else {
args.IsValid = false;
}
return;
}

关于javascript - 自定义验证器未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36720294/

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