如果我有一个具有特定验证grop的asp控件
<asp:CustomValidator ID="myRequiredValidator" runat="server" ControlToValidate="myDropDown" ClientValidationFunction="myClientSideValidationFunction" ValidateEmptyText="True" Display="None" ValidationGroup="group A"></asp:CustomValidator>
如何在javascript中更改群组?
<script type="text/javascript" language="javascript">
function changeValidationGroup(validator) { validator.ValidationGroup("group B"); }
或类似的东西?
由于
答案 0 :(得分:1)
在ASP.NET验证控件中,当呈现为HTML时,变为<span>
标记,只需将所需范围的validationGroup属性更改为新值:
<head runat="server">
<title>Validation</title>
<script src="http://code.jquery.com/jquery-1.8.2.min.js" type="text/javascript">
</script>
<script type="text/javascript">
function ChangeGroupName() {
var groupName = $("#txtGroupName").val();
if (groupName != '') {
$("#validator").attr('validationGroup', groupName);
}
};
</script>
</head>
<body>
<form id="form1" runat="server">
<input type="text" id="txtGroupName" />
<asp:CustomValidator ID="validator" runat="server" ErrorMessage="Error" ValidationGroup="Group1"></asp:CustomValidator>
<input type="button" value="OK" id="btnChangeGroup" onclick="ChangeGroupName()" />
</form>
</body>