admin管理员组文章数量:1393920
In my jsp page, I have one button and one label. When page loading, the text of the label box is "Test". Suppose, user clicks the button then I have to change the text of the label into "tested".
I am new to Jsp.So, Please guide me to get out of this issue...
In my jsp page, I have one button and one label. When page loading, the text of the label box is "Test". Suppose, user clicks the button then I have to change the text of the label into "tested".
I am new to Jsp.So, Please guide me to get out of this issue...
Share Improve this question edited Sep 27, 2019 at 22:13 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Nov 17, 2012 at 5:49 SaravananSaravanan 11.6k46 gold badges147 silver badges213 bronze badges2 Answers
Reset to default 3You would first need to set a listener to your button, say our markup was as follows:
<button id='btn'>test it</button>
<span id='label'>Test</span>
We can select the button element, and set it's onclick attribute:
document.getElementById('btn').onclick = test
Then we can define a function call test
that will toggle the label:
function test(){
document.getElementById('label').innerHTML = 'Tested';
}
And that's it!
Here's a jsfiddle demonstrating this code.
<script type="text/javascript">
function fnc()
{
document.getElementById("atext").innerHTML="tested";
}
</script>
<label id="atext">test</label>
<input type="button" onClick="fnc()" value="click me">
本文标签: javascriptHow to change the text of the label box dynamically in jsp pageStack Overflow
版权声明:本文标题:javascript - How to change the text of the label box dynamically in jsp page? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744083027a2588003.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论