在 KeyPress 上的 Javascript 中隐藏 ASP.Net 标签
我在 ASP.Net 4.0 网站上有一个标签,当用户在文本框中键入内容时我试图隐藏该标签。
我有一个 Javascript 函数,我在文本框的 Keypressevent 上触发它。
因此,我的 Javascript 函数是:
function hideLabel(sender, e) {
document.getElementById('<%=lblResult.ClientID%>').style.display = 'none';
}
我的文本框和标签如下:
<tr><td>
<asp:Label ID="lblResult" runat="server" Visible="True"></asp:Label>
</td></td>
<tr><td>
<asp:TextBox ID="txtEmailAddress" runat="server" Width="200px"
CssClass="customtxt" onkeypress="hideLabel(this, event)"></asp:TextBox>
</td></td>
该函数触发,但收到以下错误: Microsoft JScript 运行时错误:需要对象
我还在函数中尝试了以下代码行,但这并没有也不工作:
document.getElementById('lblResult').style.visibility = 'hidden';
任何人都知道为什么这在 IE 8 中失败 - 它在 Chrome 中工作正常。
I have a label on a ASP.Net 4.0 website which I'm trying to hide when the users types into a textbox.
I have a Javascript function which I'm firing on the Keypressevent of a Textbox.
So, my Javascript function is:
function hideLabel(sender, e) {
document.getElementById('<%=lblResult.ClientID%>').style.display = 'none';
}
And my textbox and labels are as follows:
<tr><td>
<asp:Label ID="lblResult" runat="server" Visible="True"></asp:Label>
</td></td>
<tr><td>
<asp:TextBox ID="txtEmailAddress" runat="server" Width="200px"
CssClass="customtxt" onkeypress="hideLabel(this, event)"></asp:TextBox>
</td></td>
The function fires but I receive the following error: Microsoft JScript runtime error: Object required
I've also tried the below line of code within my function but this doesn't work either:
document.getElementById('lblResult').style.visibility = 'hidden';
Anybody got any idea why this is failing in IE 8 - it is working correctly in Chrome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为,在您的情况下,您不需要传递任何参数来运行:
I think ,you do not need to pass any parameters to function in your case :
只是不带参数的方法就可以了。
更新:
HTML
我的标签
脚本
函数 hideIt() {
document.getElementById('<%=myLabel.ClientID%>').style.display = 'none';
}
我可以确认它确实有效......
你用的什么浏览器,我可以测试一下吗?
just method without parameters would work.
UPDATED :
HTML
My Label
SCRIPT
function hideIt() {
document.getElementById('<%=myLabel.ClientID%>').style.display = 'none';
}
I can confirm that it does work....
What browser are you using , so I can test it?
它几乎肯定会失败,因为它没有找到您正在寻找的标签。查看生成的源代码,确保标签存在于页面上,并且它具有 javascript 生成的输出中的 ID。
It's almost certainly failing b/c it's not finding the label you're looking for. Look at the generated source and make sure that the label is present on the page and that it's got the ID that is in the javascript generated output.