跨越文本输入字段?
是否可以以某种方式将跨度放置为文本输入字段的值?
我正在为一个网站制作一个邮件系统,并且想要一个漂亮的接收者输入字段,其中包含添加的接收者并将其添加到输入文本字段的值中。目前,我使用单独的“添加字段”,同时在跨度容器中显示添加的接收器。我想将这些字段合并在一起。就像常规电子邮件软件中的任何输入字段一样。
非常感谢您的帮助!提前致谢!
Is it somehow possible to place a span as the value of a text input field?
I am making a mailing system for a website and want a nice looking receivers input field, where added receivers are contained and added to the value of input text field. At the moment i use a separate "adding field" while showing added receivers in a span-container. I want to merge these to fields together. Just like any input field in regular e-mail software.
Help would be most appreciated! Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
简短的回答:不,您不能包含 >在<输入/>内。
你有几个选择。您可以使用 JavaScript 来模拟电子邮件“收件人:”字段等行为。例如,监听按键并处理 ; 后的退格键等操作。
另一种选择是使列表看起来像文本框(CSS 样式)。最后一个
EG
html:
css:
javascript (jQuery,可以更改为 vanilla)
您将需要扩展此 javascript 以包含按键处理程序等,但它给出了总体思路。
演示: http://jsfiddle.net/UeTDw/1/
但是,任何选项都需要一些 JavaScript。
如果您可以使用 jQuery,您可以查看 jQuery UI 自动完成
Short answer: no, you cannot include a <span /> within an <input />.
You have a few options. You could use javascript to emulate behaviour like the email To: field. E.g. listen to key presses and handle actions like backspace after a ;.
Another option would be to make a list appear (css styled) like a textbox. Have the last <li /> contain a textbox with cleared styles. Every time the user adds a new email then insert a new <li /> before the textbox.
E.G.
html:
css:
javascript (jQuery, can change to vanilla)
You will need to extend this javascript to include a keypress handler etc, but it gives the general idea.
Demo: http://jsfiddle.net/UeTDw/1/
Any option will require some javascript however.
If you can use jQuery, you could check out jQuery UI autocomplete
一种方法是将文本输入分层放置在样式看起来像文本输入的 div 之上。
您可以去掉接收器输入的所有样式,并向假输入添加边框、背景颜色等,使其看起来像一个文本字段。添加接收器后,您可以创建新的输入项范围并将其附加到列表中。
One way to do it would be to layer a text input on top of a div that is styled to look like a text input.
You can strip all styling off of receiver-input, and add borders, background colors, and such to fake-input so that it appears to be a text field. When a receiver is added, you can create a new input-item span and append it to the list.
输入文本字段通常用于接受原始文本输入。尝试将输入文本包装在文本字段内会导致用户错误,并且如果用户能够操作标签,则解析数据可能会遇到困难。
就我个人而言,我建议保留当前的方法,但启用某种形式的 AJAX 支持,以使用户更加动态且不易出错。
(我的 0.02 美元)
Input text fields are typically used to accept raw text input. Attempting to wrap input text inside of a text field opens you to user error and potential difficulties with parsing data if the person is able to manipulate the tags.
Personally I would suggest keeping your current method but enabling some form of AJAX support to make things more dynamic and less error-prone to the user.
(My $0.02)
TextExtjs 可能就是您想要的。它是一个 jquery 插件,允许在文本区域中使用可移动标签和自动完成等功能。
这里是一个相关的讨论 -我在哪里找到了这个插件 - 模仿 Facebook 上一些输入中发现的类似行为。
TextExtjs is probably what you want. It's a jquery plugin for allowing removable tags with autocompletion etc in a textarea.
And here is a related SO discussion - where I found this plugin - on mimicking the similar behavior found in some inputs on facebook.