jQuery - 从文本区域中删除用户输入文本
好的,我有一个设备列表,我可以在其中选择要编辑的设备。 我有 3 种编辑状态。未选择任何设备时、选择 1 个设备时或选择 x 个设备时。
我遇到的问题是,当用户在文本区域(commentField)中输入一些文本并取消编辑以编辑另一个设备时,在文本区域中输入的文本不会消失。它仍然如此,当我获得新编辑的新对话框时,注释字段具有旧注释字段中的文本(就好像它没有被清除一样)
我尝试了以下代码来删除文本(当按下取消按钮时)当我启动一个新对话框时),但没有任何效果:
$("#commentField").text(" ");
$("#commentField").value = ' ';
有没有人知道如何使用 jQuery 从文本区域中删除用户输入的文本?
提前致谢。
-雷神
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.
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 = ' ';
Is there anyone who knows how to remove user-typed text from a textarea using jQuery??
Thanks in advance.
-Thor
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您正在寻找
.val()
:示例: http://jsfiddle.net/andrewwhitaker/q6eLV/
You're looking for
.val()
:Example: http://jsfiddle.net/andrewwhitaker/q6eLV/
由于
textarea
是一个输入字段,它有一个value
属性,因此您必须使用val()
方法。试试这个Since
textarea
is a input field it has avalue
property so you have to useval()
method. Try this在 jQuery 中,它实际上是
$("#commentField").val(" ");
In jQuery it's actually
$("#commentField").val(" ");
您可以从文本区域中删除文本,如下所示:
编辑:这不起作用,但我真的很想知道为什么。我一直认为
textarea
标签之间的文本是innerHTML,而html()
应该替换它。像输入这样的文本区域没有意义吗?或者只是因为文本区域包含大量文本,这些文本在引号之间看起来很俗气?使用常规的 javascript 和innerHTML,它在 FF6 中对我有用。
此处演示
You can remove text from the textarea like this:
EDIT: this does not work, but I'd be really interested as to why. I always thought that the text between the
textarea
tags was innerHTML andhtml()
is supposed to replace just that. Wouldn't it make sense to have textarea like input? or is it just because textareas contain long amounts of text that would look tacky between quotation marks?.Using regular javascript with innerHTML it works for me in FF6.
demo here
1)
2)
CKEDITOR.replace('editor1');
3)
启动 = true;
在文本区域写入文本
1)
$("#editor1").val("您的输入值");
清理您的文本区域
1)
$("#editor1").reset();
为你阅读这篇文章而加油。
1)
<textarea name="editor1" id="editor1" rows="10" cols="80"></textarea>
2)
CKEDITOR.replace('editor1');
3)
initiated = true;
to write your text in you text area
1)
$("#editor1").val("your input value");
to clean your text area
1)
$("#editor1").reset();
tank you for reading this.