gpt4 book ai didi

javascript - 将自定义验证器动态附加到控件时出现问题

转载 作者:行者123 更新时间:2023-12-02 20:26:20 25 4
gpt4 key购买 nike

有人知道为什么这段代码不起作用吗?

<script type="text/javascript">
function BookDeskValidation(source, arguments) {
var deskCombo = $find("<%=RadComboBoxDesk.ClientID%>");
var bookCombo = $find("<%=RadComboBoxBook.ClientID%>");
if (bookCombo.get_text() != "" && deskCombo.get_text() == "") {
arguments.IsValid = false;
}
else {
arguments.IsValid = true;
}
}

function AttachValidator(combobox) {
var validator = document.getElementById("<%= CustomValidatorDeskBook.ClientID %>");
validator.controltovalidate = combobox.get_id();
validator.ClientValidationFunction = "BookDeskValidation";
ValidatorHookupControl(combobox, validator);
}
</script>

<td>Book:&nbsp;</td>
<td>
<telerik:RadComboBox ID="RadComboBoxBook" runat="server" OnClientFocus="AttachValidator">
</telerik:RadComboBox>
</td>

<td width="70">Desk:&nbsp;</td>
<td width="100">
<telerik:RadComboBox ID="RadComboBoxDesk" runat="server" OnClientFocus="AttachValidator">
</telerik:RadComboBox>
</td>
<asp:CustomValidator ID="CustomValidatorDeskBook" runat="server"
ErrorMessage="Error"
ClientValidationFunction="BookDeskValidation" ForeColor="Red">*</asp:CustomValidator>

OnClientFocus 已启动,但自定义验证器似乎并未附加,因为当我退出应附加验证器的控件时,不会进行任何验证。

谢谢!

最佳答案

好的,我成功完成了这项工作。这就是我所做的。如果有人知道更好的方法,或者如果我解决问题的方法不正确,请告诉我!

这就是我所做的:

<script type="text/javascript">
function BookDeskValidation(source, arguments) {
var deskCombo = $find("<%=RadComboBoxDesk.ClientID%>");
var bookCombo = $find("<%=RadComboBoxBook.ClientID%>");
if (bookCombo.get_text() != "" && deskCombo.get_text() == "") {
arguments.IsValid = false;
}
else {
arguments.IsValid = true;
}
}

function AttachValidator(combobox) {
var validator = document.getElementById("<%= CustomValidatorDeskBook.ClientID %>");
validator.ControlToValidate = combobox.get_id();
}

function EnableValidator(combobox) {
var validator = document.getElementById("<%= CustomValidatorDeskBook.ClientID %>");
ValidatorEnable(validator, true);
}
</script>

<td>Book:&nbsp;</td>
<td>
<telerik:RadComboBox ID="RadComboBoxBook" runat="server" OnClientFocus="AttachValidator" OnClientDropDownClosed="EnableValidator">
</telerik:RadComboBox>
</td>

所以基本上我摆脱了 ValidatorHookupControl 函数,并将其替换为 OnClientDropDownClosed 事件上的 ValidatorEnable

关于javascript - 将自定义验证器动态附加到控件时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4795437/

25 4 0
文章推荐: javascript - 只允许在 contentEditable
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com