从另一个文本框动态更改文本框文本 [英] Change textbox text dynamically from another textbox

查看:92
本文介绍了从另一个文本框动态更改文本框文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

我正在尝试从另一个文本框动态更改一个文本框文本.当我在第一个文本框中书写时,我正在书写的文本必须出现在第二个文本框中.请帮忙!

谢谢,对不起,英语不好.

Hi!

I''m trying to change a textbox text dynamically from another textbox. When i''m writing in the first textbox, the text that i''m writing must appare in the second textbox. Please help!

thanks, sorry for the bad english.

推荐答案

最好在纯Javascript客户端执行此操作,因为回传此类频繁事件将使性能不可接受.方法如下:

It''s the best to do it at client side in pure Javascript as post back for such a frequent event will make performance unacceptable. Here is how:

<html>
<head>
<title>Copy text box text on each change</title>

<script type="text/javascript">

function copyText() {
    src = document.getElementById("source");
    dest = document.getElementById("dest");
    dest.value = src.value;
}

</script>
</head>

<body>
   <input type="text" id="source" onKeyPress="copyText()">
   <input type="text" id="dest">
</body>
</html>



它可以正常工作,经过测试.
我似乎没有任何实际意义.希望这仅仅是一个练习.

—SA



It works, tested.
I does not seem to have any practical sense though. Hope this is a mere exercise.

—SA


查看TextBox类的TextChanged事件.
Look into the TextChanged event of the TextBox class. It''s very easy to do from there.


<html>
<head>
<script type="text/javascript">
    function copy_data(val){
     var a = document.getElementById(val.id).value
     document.getElementById("copy_to").value=a
    }

    </script>
</head>
<body>
<center>
From:<input type="text" name ="a" id="copy_from" onkeyup="copy_data(this)"/><br>
To:<input type="text" name ="b" id="copy_to"/><br>
</center>
</body>
</html>


这篇关于从另一个文本框动态更改文本框文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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