如何从文本框中删除文本 [英] How to remove the text from textbox

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

问题描述

大家好,



我已经为文本框分配了一个默认的文本字符串。现在我想如果有人点击该文本框,文本框中的值将被删除。



i我使用下面的代码,但它不起作用并给我一个错误。

  public   void  TextBox_GotFocus( object  sender,RoutedEventArgs e)
{
TextBox tb =(TextBox)sender;
tb.Text = string .Empty;
tb.GotFocus - = TextBox_GotFocus;
}



任何人都可以帮我解决这个问题。

解决方案

使用ASP来自 WaterMark Textbox 的.NET WaterMark文本框[ ^ ]。它位于 Ajax Toolkit

也可以查看..

^ ]

http://oneaonej.blogspot.com/2012/10/ajax-control-toolkit-textboxwatermark.html [ ^ ]

http://www.aspdotnet-suresh .com / 2011/10 / how-to-create-watermark-textbox-using.html [ ^ ]


请试试这个。



< input type =textplaceholder =mm / dd / yy onblur =if(this.value ==''){this.placeholder ='mm / dd / yy'; this.style.color ='#293f46';}autocomplete =offid =datepickerstyle =color: rgb(41,63,70);/>





演示网址

演示网址


试试这个:



 <   asp:TextBox    < span class =code-attribute> ID   =  new_range1    onChange   =  newobjCompute()      onFocus   =  this.value =''; return false;    runat   =  server    BorderWidth   =  0px   高度  =  47px  
< span class =code-attribute> < span class =code-attribute> 宽度 = 90px style = text-align:center > 0 < / asp:TextBox >





看到onFocus标签?首先为文本框设置一个值。如果单击文本框,它将删除默认值为null。


Hi All,

i have assigned a default string of text to a text box. now i want if someone click on that textbox, value inside the textbox gets removed.

i am using below code but its not working and giving me an error.

public void TextBox_GotFocus(object sender, RoutedEventArgs e)
{
   TextBox tb = (TextBox)sender;
   tb.Text = string.Empty;
   tb.GotFocus -= TextBox_GotFocus;
}


can anyone please help me in resolving this issue.

解决方案

Use a ASP.NET WaterMark textBox from WaterMark Textbox[^]. It is in Ajax Toolkit.
Also can view..
How to used watermark in asp.net for Textbox[^]
http://oneaonej.blogspot.com/2012/10/ajax-control-toolkit-textboxwatermark.html[^]
http://www.aspdotnet-suresh.com/2011/10/how-to-create-watermark-textbox-using.html[^]


Please try this.

<input type="text" placeholder="mm/dd/yy" onblur="if(this.value==''){ this.placeholder='mm/dd/yy';this.style.color='#293f46';}" autocomplete="off" id="datepicker" style="color: rgb(41, 63, 70);"/>


Demo URL
Demo URL


try this one:

<asp:TextBox ID="new_range1" onChange="newobjCompute()"  onFocus="this.value=''; return false;" runat="server" BorderWidth="0px" Height="47px"
                           Width="90px" style="text-align: center">0</asp:TextBox>



see the "onFocus" tag? set a value for your textbox first. if you click the textbox, it will delete the default value to null.


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

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