如何从错误填充的Textarea中删除值 [英] How Can I Delete Values From A Textarea That Have Been Filled By Mistake

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

问题描述

我创建了一个textarea,我可以在自动完成的帮助下填充值,但我想要更多,应该有一个十字标志或其他东西,所以如果有人错误地填写了一个值,那么他/她可以删除它按下那个十字架,我不想通过按退格键手动完成。请帮我或告诉我一些逻辑怎么做

I have created a textarea in which i can fill values with the help of auto completion but i want more , there should be a cross sign or something else so if anyone have filled a value by mistake so he/she can delete it by pressing that cross and i don't want to do it manually by pressing backspace.Please help me or tell me some logic how to do it

推荐答案

没有你想要的WPF中的这种功能。但是,您可以在WPF中创建自己的控件,或者可以使用其他控件并将其与其他控件重叠。例如,考虑以下XAML标记,



There is no such function in WPF that you want. However, you can create your own controls in WPF or you can use other controls and overlap them over other controls. Such as, think of the following XAML markup,

<textbox name="myTextBox" />
<textblock name="myTextBlock" margin="0, -20, 0, 0">
           HorizontalAlignment="Right"
           MouseRightButtonUp="changeText">X</textblock>





..现在这会与TextBox重叠,假设高度和填充没有干预来改变控件的对齐方式。



现在已经设置了应用程序的UI,您可以使用 Visibility =Visible Visibility =Collapsed更改应用程序中X标记的可见状态。



现在,要删除在TextBox中写的文字,你可以这样做,





.. now this would overlap the TextBox, assuming the height and paddings don't intervene to change the aligment of the controls.

Now the UI of the application has been set, you can use the Visibility="Visible" or Visibility="Collapsed" to change the visible state of the X mark in the application.

Now, to remove the text written in the TextBox, you can do this,

void changeText(object sender, EventArgs e) {
   // if you want to remove the text, then 
   myTextBox.Text = ""; // clear the text property

   /* ------------------------------------------
    * if you want to remove the last character 
    * change the text property of it, to its own text but without last character */
   myTextBox.Text = myTextBox.Text.Substring(0, myTextBox.Text.Length - 1);
}





还有很多其他方法可供使用,但我想到了这个方法。试一试,并在你的应用程序中使用它。



There are many other methods that can be used, but this one came to my mind. Do give it a try, and use it in your application.


不确定你的textarea自动完成是如何工作的,但是这里有一个使用jQuery,html和css的可能解决方案。



为每个textarea创建一个叠加十字(div),点击后将从关联的textarea中删除内容。

也只显示叠加十字架( div)当textarea内容有内容时。

Not sure how your textarea auto completion is working, but here is a possible solution using jQuery, html and css.

An overlay cross (div) is created for each textarea, when clicked will remove content from the associated textarea.
Also only displays the overlay cross (div) when textarea content has content.
.AutoCompleteOverlayContainer{
    position:relative;
    display:inline-block;
}
.AutoCompleteOverlayContainer textarea{
    padding-right: 1em;
}
.AutoCompleteOverlayContainer div{
    position:absolute;
    right:0; 
    top:0; 
    width:1em;
    height:1em;
    cursor: context-menu;
    border: solid 2px #aaaaaa;
    text-align:center;
    font-weight:900;
    background-color: #ffffff;
    color: #ff0000;
}




<textarea>I have some text</textarea>
<textarea></textarea>
<textarea>I have some text</textarea>
<textarea>I have some text</textarea>





document )。ready( function (){
var classOverlay = ' AutoCompleteOverlayContainer';
// 操纵textarea列表以放置所需的包装和兄弟元素
(document).ready(function(){ var classOverlay='AutoCompleteOverlayContainer'; //manipulate textarea list to put in place desired wrapper and sibling elements


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

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