gpt4 book ai didi

javascript - setAttribute 不起作用

转载 作者:行者123 更新时间:2023-12-02 17:41:49 26 4
gpt4 key购买 nike

此代码嵌套在 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>

最佳答案

你的方式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!');

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

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