简体   繁体   English

文本框自动返回值

[英]Textbox automatically return value

I am planning to create a .aspx and .cs file. 我打算创建一个.aspx和.cs文件。 All I have is basically 2 textbox. 我基本上只有2个文本框。

文本框

(Please disregards the button in the middle.) (请忽略中间的按钮。)

the first textbox is to input the sentence, and I want the other textbox automatically following what I type in the first box. 第一个文本框用于输入句子,我希望另一个文本框自动跟随在第一个文本框中输入的内容。 So basically its similar like google translate, but it's not translating the text. 因此,基本上与Google翻译类似,但不翻译文本。 Just simply following the text I input in the first textbox. 只需跟随我在第一个文本框中输入的文本即可。

Any Idea how to do it? 任何想法怎么做?

You can also achieve this using JavaScript , see attached code sample. 可以做到这一点使用JavaScript ,请参阅附带的代码示例。

It uses onKeyUp event for html inputs ' , in your code replace input control ids with clientid snippets as indicated in comments. 它将onKeyUp事件用于html inputs ',在代码中将输入控件id替换为clientid片段,如注释中所示。

Also see this - how to add onKeyUp to asp.net textbox to make this happen in your code. 另请参阅此内容- 如何将onKeyUp添加到asp.net文本框中以使此过程在代码中发生。

 function copyText() { //var textBoxFirstClientID = '<%= textBox1.ClientID %>'; //var textBoxSecondClientID = '<%= textBox2.ClientID %>'; var txt1 = document.getElementById('txt1');// use textBoxFirstClientID var txt2 = document.getElementById('txt2');//use textBoxSecondClientID txt2.value = txt1.value; } 
 <asp:textbox id="textBox1">your asp.net textbox 1</asp:button> <input type="text" id="txt1" onkeyup="copyText()"> <br> <br> <asp:textbox id="textBox2">your asp.net textbox 2</asp:textbox> <input type="text" id="txt2" /> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM