gpt4 book ai didi

javascript - 验证器启用不起作用

转载 作者:行者123 更新时间:2023-11-30 05:34:49 25 4
gpt4 key购买 nike

我的代码如下

<asp:DropDownList ID="ddlFilter" runat="server" onchange="ShowHideSearchTextBox(this)">
<asp:ListItem Value="0">--Select--</asp:ListItem>
<asp:ListItem Value="customer_name">Customer Name</asp:ListItem>
<asp:ListItem Value="order_number">Order Number</asp:ListItem>
<asp:ListItem Value="Pending">Dispatch Pending</asp:ListItem>
<asp:ListItem Value="Done">Dispatch Done</asp:ListItem>
</asp:DropDownList>

<script type="text/javascript">
function ShowHideSearchTextBox(me) {
var searchBox = document.getElementById("searchBox");
var validator = document.getElementById(" <%= RequiredFieldValidator1.ClientID%> ");
if (me.value == "Pending" || me.value == "Done") {
ValidatorEnable(validator, false);
searchBox.style.display = "none";
}
else {
ValidatorEnable(validator, true);
searchBox.style.display = "block";
}
}
</script>

无论我在下拉列表中选择什么值,我的验证器始终处于事件状态。我错过了什么?

编辑

validator 的值即将到来null

最佳答案

您好,我假设您的验证器已正确实现,所以他们的问题在于您如何在 javascript 中访问验证器:

var validator = document.getElementById(" <%= RequiredFieldValidator1.ClientID%> ");

将其更改为:

var validator = document.getElementById("<%= RequiredFieldValidator1.ClientID %>");

删除引号内多余的空格应该可以解决问题,因为 getElementById 不会为您删除空格。

测试了您上面的代码(使用有效的验证器),更改解决了问题。

关于javascript - 验证器启用不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24568794/

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