如何写一个JavaScript [英] how to write a javascript

查看:93
本文介绍了如何写一个JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本框和一个按钮.无论我在文本框中写什么,都应该在标签上显示.这将是我的代码

I have a text box and a button.whatever i write in the text box it should be displayed on a label.what will be my code

推荐答案

使用如果要在文本框的文本更改时显示在标签上,则文本框的onChange事件

或者您可以使用按钮的onClick事件

use onChange event of the textbox if you want to display on label on textchange of the textbox

or you can use button''s onClick event

function Test(value){
document.getElementById('span or label Id').innerHTML=value;
}

<input type="text"  önchange="Test(this.value" />


这有点简单,只需单击按钮,就需要设置要标记的文本.
< head> 标签下写一个javascript

This is bit easy. on button click you need to set text to label.
write a javascript under <head> tag

<script language="Javascript">
function setLabel()
{
  //set label value by collecting text from textbox
  document.getElementById("Label1").innerHTML = document.getElementById("Txt1").value;
  return false;
}
</script>
</script>



在按钮单击上方调用javascript函数



call above javascript function on button click

<asp:button id="BtnId1" runat="Server" value="SerText" onclientclick="return setLabel()">


这篇关于如何写一个JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆