Javascript 通过 insidehtml 更改标签文本不起作用
我有这个 javascript
函数:
function validateFile() {
var file = document.getElementById('fuCSV');
if (file.value == "") {
document.getElementById('<%=lblStatus.ClientID%>').innerhtml = "Please select a file to upload. Client!";
return false;
}
else {
document.getElementById('<%=lblStatus.ClientID%>').innerhtml = "";
return true;
}
}
它在按钮的 OnClientClick
事件上调用,如下所示:
<asp:Button ID="btnImport" runat="server" Text="Import" OnClientClick="return validateFile();" CausesValidation = "true"
UseSubmitBehavior ="true" OnClick="btnImport_Click" />
我正在尝试更改标签 lblStatus
的文本validateFile()
方法,但文本没有改变。但是,在调试时...QuickWatch 显示更改后的值。可能是什么原因造成的?我该如何解决这个问题?
I have this javascript
function:
function validateFile() {
var file = document.getElementById('fuCSV');
if (file.value == "") {
document.getElementById('<%=lblStatus.ClientID%>').innerhtml = "Please select a file to upload. Client!";
return false;
}
else {
document.getElementById('<%=lblStatus.ClientID%>').innerhtml = "";
return true;
}
}
Its called on the Button's OnClientClick
event like this:
<asp:Button ID="btnImport" runat="server" Text="Import" OnClientClick="return validateFile();" CausesValidation = "true"
UseSubmitBehavior ="true" OnClick="btnImport_Click" />
I'm trying to change the text of the label lblStatus
on validateFile()
method, but the text is not changing. However, while debugging...QuickWatch shows the changed value. What might be the cause for it? how can I resolve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我曾建议使用
innerText
但显然,符合 W3C 的方法是使用 textContent:请参阅 Mozilla 文档位于此处。
I had suggested to use
innerText
but apparently, the W3C-compliant way of doing this is to use textContent:See Mozilla's documentation here.
在属性上使用正确的大小写:innerHTML
http://www.tizag.com/javascriptT/javascript -innerHTML.php
Use correct casing on the property: innerHTML
http://www.tizag.com/javascriptT/javascript-innerHTML.php
JavaScript 区分大小写,如果您设置
innerhtml
属性而不是innerHTML
,您将看不到任何内容。Javascript is case sensitive, if you set
innerhtml
property instead ofinnerHTML
you won't see anything.获取要在 e 中提供输出的 id。
get the id where you want to give output in e.