将输入文本更改为模糊的常规文本并能够编辑 jQuery
我正在创建一个表单,其中不再使用保存按钮。该表单由输入文本框和文本区域组成。用户在输入字段中输入数据后,我想触发 onBlur 函数并将输入更改为包含用户输入的信息的范围。
我还希望能够编辑这些信息,因此,如果用户单击新创建的文本范围,它将返回到包含当前信息的输入字段,以便他们进行编辑。
作为参考,我希望有一个非常类似于在 Flickr 上编辑照片标题的功能。
如果可能的话,我还想让文本框在模糊后显示“正在保存...”半秒,以反映与服务器的交互。
I'm creating a form where I'm eliminating the use of a save button. The form is made up of input text boxes and textareas. After the user enters data into the input field, I want to trigger an onBlur function and change the input into a span that contains the information that the user entered.
I also want to have the ability to edit this information, so if the user clicks on the newly created span with text, it will turn back into the input field with the current information for their editing pleasure.
For reference, I'm looking to have a functionality pretty much like on editing a photo title on Flickr.
If possible, I'd also like to have the textbox show "saving..." for half a second after the blur to reflect interaction with server.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为什么不为输入创建一个 CSS 样式
:focus
,使其看起来像一个文本框,或者创建一个 CSS 样式,使其看起来像一个内联文本元素?Why not make a CSS style for
:focus
for the input, making it look like a text-box, and a CSS style otherwise which makes it look like an inline text element?我根据@strager的建议进行了尝试,并编写了以下功能出色的代码
jQuery:
和 CSS:
I played around with this based on @strager's suggestions and composed the following, excellently functional code
jQuery:
and CSS:
我不太清楚您所指的 Flickr 上的功能,但也考虑根本不更改输入的类型,而只是更改其样式。无需摆弄 DOM,就变得更容易、更可行。像这样的设置
会使文本输入看起来像一个跨度。
这样做的缺点是,与
不同,文本输入始终具有固定宽度。
I don't exactly know the function on Flickr you're referring to, but also consider not changing the input's type at all, but just its style. Much easier and doable without fiddling in the DOM. A setting like
would make a text input look like a span.
A downside to this is that a text input, different from a
<span>
, always has a fixed width.