gpt4 book ai didi

javascript - 使用 JavaScript 禁用 ASP.NET 1.1 验证器 - 在 Firefox 中不起作用

转载 作者:行者123 更新时间:2023-11-28 02:51:40 24 4
gpt4 key购买 nike

以下尝试在 IE8 中有效,但在 Firefox 中无效(不能为此使用 JQuery):

case 'Template:templateControl:residenceRBL2': 
if (selected.value == 'Within USA')
{
/* Enable zip textbox and validator */
document.getElementById("Template_templateControl_zipTxt1").disabled=false;
ValidatorEnable(document.getElementById('<%=firstPersonZipReqVal.ClientID%>'),
true);
...
}
else if (selected.value == 'Outside USA')
{
/* Disable zip textbox and validator */
document.getElementById("Template_templateControl_zipTxt1").disabled=true;
ValidatorEnable(document.getElementById('<%=firstPersonZipReqVal.ClientID%>'),
false);
...
}
break;

<asp:Label ID="firstPersonZipLabel" Runat="server"></asp:Label><br />
<asp:TextBox ID="zipTxt1" Height="19" Width="100"
Runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="firstPersonZipReqVal"
ControlToValidate="zipTxt1" Display="Dynamic"
ErrorMessage="First Person Zip"
Runat="server">*</asp:RequiredFieldValidator>

问题描述:根据单选按钮列表的选择,文本框所需的验证器被禁用/重新启用。基本上,如果他们的地址位于美国境外,则 zip 文本框验证器将被禁用。在 Firefox 中,这根本不起作用。

更新 1:2010 年 9 月 7 日我在 Firefox 中禁用了文本框;我使用的是 name 属性而不是 id。我现在唯一的问题是如何在 JS 中访问 ASP.NET 验证器控件的“ClientID”?

更新 2:2010 年 9 月 7 日根据 MSDN documentation ,我想我可以做这样的事情:

ValidatorEnable(firstPersonZipReqVal, false);

不幸的是,这似乎在 Firefox 中也不起作用......

ASP.NET broken rendering of Validation client side code in Firefox

更新 3:2010 年 9 月 8 日

Firefox 表现不佳的原因是 ASP.NET 1.1 将其视为低级浏览器。如果我将 clientTarget="upLevel"放在 Page 标签中,Firefox 将按预期工作。不幸的是,这破坏了整个网站的布局。 是否有更渐进的方法来修复 Firefox 的浏览器上限? This version browserCaps 也会破坏布局。

Web.Config 中当前的 browserCap 如下所示:

 <browserCaps> 
<case match="Gecko/[-\d]+">
browser=Netscape
frames=true
tables=true
cookies=true
javascript=true
javaapplets=true
ecmascriptversion=1.5
w3cdomversion=1.0
css1=true
css2=true
xml=true
tagwriter=System.Web.UI.HtmlTextWriter
<case match="rv:1.0[^\.](?'letters'\w*)">
version=6.0
majorversion=6
minorversion=0
<case match="^b" with="${letters}">
beta=true
</case>
</case>
<case match="rv:1(\.\d+)(\.\d)?(?'letters'\w*)">
version=7.0
majorversion=7
minorversion=0
<case match="^b" with="${letters}">
beta=true
</case>
</case>
</case>
</browserCaps>

更新:2010 年 9 月 11 日

以下链接可能会提供答案;有人可以帮忙提供 50 分的代码吗?

https://web.archive.org/web/20211020134119/https://www.4guysfromrolla.com/articles/051204-1.aspx

最佳答案

how to access the "ClientID" of an ASP.NET validator control in JS

您正在代码中以正确的方式访问它,尽管您可能需要使用双引号而不是单引号:

document.getElementById("<%=firstPersonZipReqVal.ClientID%>")

关于javascript - 使用 JavaScript 禁用 ASP.NET 1.1 验证器 - 在 Firefox 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3640183/

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