使用 jQuery 的可编辑文本功能
我有一个图像按钮,当我单击它时,我想要一个特定字段从文本变为可编辑文本字段,有点像动态编辑按钮。
所以我有带有特定 id 的纯文本(即 id="text1"),当我单击按钮时,文本会更改为可编辑字段,可能类似于 $("#text1").hide() ;
然后 $("#field1").show();
但在中间我需要为字段提供文本的值,然后当我单击按钮保存时应该隐藏输入字段并只显示带有新值的文本。
任何帮助将不胜感激。
谢谢:D
I have an image button and when I click it I want an specific field to go from text to an editable textfield, kinda like a dynamic edit button.
So I have the plain text with certain id (ie. id="text1") and when I click the button, the text changes to an editable field, maybe something like $("#text1").hide();
and then $("#field1").show();
but in between I need to give the field the value of the text, and then when I click the button save I should hide the input field and just show the text with the new value.
Any help will be greatly appreciated.
Thanks :D
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
给定一个输入字段、一个带有
id="text1"
的 paragraph 和一个按钮。这个简单的 jQuery 将从段落中复制文本,隐藏它并显示带有段落文本的输入。
这是一个示例。
只是为了好玩,我编写了一个小脚本,可以启用段落的
功能。只需将.editable
类添加到任何段落,jQuery 就会处理剩下的事情。我还没有扩展它以允许多次编辑,而且我几乎开始编写保存到数据库的 AJAX 调用,因为我很无聊。 但是因为阳光明媚,我想我宁愿去海滩。这是我的代码和示例。示例
你真的不需要所有 ID,但如果您要使用新值执行 POST,则可以轻松引用这些元素。
Given an input field, a paragraph with
id="text1"
and a button.This simple jQuery will copy the text from the paragraph, hide it and show the input with the text from the paragraph.
Here's a sample.
Just for fun, I've written a small script that enables
<editable>
functionality for paragraphs. Just add a class of.editable
to any paragraph and jQuery takes care of the rest. I haven't extended it to allow multiple edits and I almost started writing AJAX calls that save to the database because I'm bored. But since the sun is shining I thought I'd rather go to the beach. Here's my code and a sample.SAMPLE
You really don't need all the ID's but if you're gonna do a POST with new values, you can easily refer to the elements.
还不错。文本进入文本字段的值区域。因此,从文本区域获取它,将其保存在临时变量中,然后将其放入文本字段中。
实际上,你甚至不需要我认为不需要的温度,它应该看起来像
“注意这是未经测试的”。您可能会发现这篇文章也很有价值。
Not too bad. The text goes into the value area of the text field. So get it from the text area, save it in a temp variable, and put it in the textfield.
Actually, you don't even need the temp I don't think, it should look something like
Note this is untested. You might find this SO article to be of value as well.