jQuery-从textarea删除用户输入的文本 [英] jQuery - remove user input text from textarea

查看:113
本文介绍了jQuery-从textarea删除用户输入的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我有一个设备列表,可以在其中选择要编辑的设备. 我有3种状态可供编辑.如果未选择任何设备,则选择1个设备或选择x个设备.

Okay I have a list of devices where i can select which to edit. I have 3 states for the edit. When no devices are selected, when 1 device is selected or when x devices are selected.

我遇到的问题是,当用户在textarea(commentField)中键入一些文本并取消编辑以编辑另一台设备时,在textarea中键入的文本不会消失.它保持不变,当我获得新对话框进行新编辑时,commentfield包含了旧commentField中的文本(好像没有清除)

The problem i have is when a user type some text in the textarea (commentField) and cancels the edit to edit another device, the text there was typed in the textarea won't disapere. It stays so when i get the new dialog for the new edit, the commentfield has the text from the old commentField (as if it wasn't cleared)

我尝试使用以下代码删除文本(在按下取消"按钮时和在启动新对话框时),但是没有任何效果:

I have tried the following codes to remove the text (both when then cancel button is pressed and when i start a new dialog), but nothing works:

$("#commentField").text(" ");
$("#commentField").value = ' ';

有没有人知道如何使用jQuery从文本区域删除用户键入的文本?

Is there anyone who knows how to remove user-typed text from a textarea using jQuery??

谢谢.

-雷神

推荐答案

您在寻找 .val() :

$("#commentField").val('');

示例: http://jsfiddle.net/andrewwhitaker/q6eLV/

这篇关于jQuery-从textarea删除用户输入的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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