我需要按按钮更改文本框内容。例如,
首次点击按钮时,a
应为内容。要再次单击某个按钮,b
应为内容。比如T9 Keyboard
。
我的代码,只显示a
没有显示其他字母。
我的代码;
private void buttonFor1(object sender, EventArgs e)
{
var count = 0;
count++;
if (count == 1)
{
messageText.Text = "a";
}
else if (count == 2)
{
messageText.Text = "b";
}
else if (count == 3)
{
messageText.Text = "c";
}
}
答案 0 :(得分:0)
在JavaScript中
<html>
<script type="text/javascript">
var count=0;
function Button_Click()
{
count++;
var txtBox=document.getElementById('txtAlpha');
if(count==1)
{
txtBox.value="a";
}
else if(count==2)
{
txtBox.value="b";
}
else if(count==3)
{
txtBox.value="c";
}
}
</script>
<input type="button" value="click" onclick="Button_Click()"/>
<input type="text" id="txtAlpha"/>
</html>
这是你想要的。如果这是你想要实现的,你可以替换if else子句相应地使用a / b / c的ascii值,
1将转换为a,2将转换为b等。
根据您的要求在C#中:
static int count=0;// Global Variable declare somewhere at the top
protected void Button1_Click(object sender, EventArgs e)
{
count++;
if (count == 1)
{
TextBox1.Text = "a";
}
else if (count==2)
{
TextBox1.Text = "b";
}
else if (count == 3)
{
TextBox1.Text = "c";
}
}
希望你明白我的观点!!
干杯!!!
答案 1 :(得分:0)
public void button1_Click(object sender, EventArgs e)
{
if (messageText.Text == "")
messageText.Text = "a";
else if(messageText.Text == "a")
{
messageText.Text = "b";
}
else if (messageText.Text == "b")
{
messageText.Text = "c";
}
else
{
messageText.Text = "";
}
}