此代码嵌套在ascx控件中。 onclientclick事件有效,没有错误,但标签文本没有改变?我错过了什么?
<asp:Button
ID="btnUpload" runat="server" CssClass="Uploadbtn1" OnClientClick="BePatient()" OnClick="btnUpload_Click"
Text="Upload" Width="62px" align="center"/>
<Label ID="Label1" ></Label>
<br />
<br />
<asp:Label ID="ErrorMessageLbl" runat="server"></asp:Label>
<script type="text/javascript" language="javascript">
function BePatient() {
var lbl = document.getElementById('<%=ErrorMessageLbl.ClientID%>');
var lblText = lbl.getAttribute("innerText");
// var lblText = lbl.getAttribute("Text"); // this did not work
//var lblText = lbl.getAttribute("innerHtml"); // this did not work
lbl.setAttribute(lblText, "Please be patient this will take awhile!");
}
</script>
答案 0 :(得分:2)
你set an element's text的方式如下:
var lbl = document.getElementById('<%=ErrorMessageLbl.ClientID%>');
lbl.innerText = "Please be patient this will take awhile!";
如果出于某种原因你真的想要设置一个名为'innerText'的属性,那么你可以使用
var lbl = document.getElementById('<%=ErrorMessageLbl.ClientID%>');
lbl.setAttribute('innerText', 'Please be patient this will take awhile!');