文本框值的问题 [英] problem with textbox value

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

问题描述

我有两个文本框。我想根据我在第一个文本框中输入的内容更改第二个文本框值。意思是假设我在第一个文本中输入5,然后值50应该在第二个文本框中。 PLZ帮帮我?

I have two textboxes.I want to change 2nd textbox value according to whatever i entered in 1st textbox..means suppose i enter 5 in first text and then value 50 should come in 2nd textbox. plz help me?

推荐答案

你需要处理TextBox1_TextChanged事件。



protected void TextBox1_TextChanged(object sender,EventArgs e)

{

int example = Convert.ToInt32(Textbox1.Text * 10);

Textbox2.Text = Convert。 ToString(示例);

}



更改AutoPostBack属性对于TextBox1更新。





它会显示。

TextBox1 TextBox2



1 ------ -----> 10

2 -----------> 20

3 ---------- - > 30

4 -----------> 40

5 -----------> 50





希望它会对你有帮助。
You need to work on TextBox1_TextChanged event.

protected void TextBox1_TextChanged(object sender,EventArgs e)
{
int example=Convert.ToInt32(Textbox1.Text*10);
Textbox2.Text=Convert.ToString(example);
}

Change the AutoPostBack property As true for TextBox1.


It will display.
TextBox1 TextBox2

1----------->10
2----------->20
3-----------> 30
4-----------> 40
5-----------> 50


Hope it will help you.


上次,请试试这么小的东西靠自己而不是在这里提问。你需要学习并付出一些努力。



步骤:

1.为textbox1定义onblur或onfocusout事件(如果服务器控件然后通过属性添加)

2.在JavaScript中定义相关方法

3.在此方法中,获取textbox1的值,然后根据它设置textbox2中的值



你可能需要知道:

如何在JS中访问文本框值:
Last time, please try such small things by yourself instead of asking questions here. You need to learn and make some effort.

Steps for your thing:
1. Define a onblur or onfocusout event for the textbox1 (if server control then add through attributes)
2. Define the related method in JavaScript
3. In this method, get the value of textbox1 and then based on it set the value in textbox2

You might need to know:
How to access textbox value in JS:
document.getElementById("textbox1").value



如何通过代码添加属性:


How to add attribute via code:

textbox1.Attributes.Add("onblur","javascript: GetT1ValueAndSetT2(this);");





整体来说,

HTML:



So overall,
HTML:

<asp:TextBox ID="txtValue1" runat="server" ></asp:TextBox>
<asp:TextBox ID="txtValue2" runat="server"  ></asp:TextBox>





和Javascript



and Javascript

<script type="text/javascript">
  function GetT1ValueAndSetT2(txtValue1)
  {
     document.getElementById("txtValue2").value=parseFloat(txtValue1.value,10)*5;
  }

</script>



立即尝试。


Try now.






您可以使用jquery来解决问题。请尝试下面的解决方案,

Hi,

You can use jquery to solve the issue. Try this solution below,
<script  type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript">


这篇关于文本框值的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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