javascript error with label
I have a function as follows:
function textNext(element, num) {
document.getElementById("lblContent").innerH开发者_如何学CTML = "hello";
}
However, the text of the lblContent
label won't change when the function is called.
What am I doing wrong?
btw : lblContent is of type asp:Label
Since lblControl
is a server side ASP.NET control, you will need to use the control ClientID
property in order to use it in javascript:
function textNext(element, num) {
document.getElementById(<"%=lblContent.ClientID%>").innerHTML = "hello";
}
Check the console in your browser for errors. I tried to reproduce your problem in a standard HTML/Javascript environment.
This works for me.
<html>
<head>
<title>Test</title>
<head>
<body>
<div id="lblContent">Previous text</div>
<a href="#" onclick="textNext()">Change text</a>
<script type="text/javascript">
function textNext() {
document.getElementById("lblContent").innerHTML = "Next text";
}
</script>
</body>
</html>
精彩评论