当我键入逗号时,如何在输入标签中添加更多图标
I'm wondering how can I add more icon, when I keydown comma inside input tag
before input comma
after input comma
is there any plugins or reference code? please let me know
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以为
键UP
事件添加EventListener,如果按下键并释放了一个键。事件接口提供了代码
属性,其中包含按下的密钥的代码。如果此代码
是“逗号”,则在输入的值中添加You can add an EventListener for the
keyup
event, that is fired, if a key was pressed and is released. The event interface proviedes acode
property, that contains the code of the key that was pressed. If thiscode
is "Comma", you add a ???? (or any other character or icon) to the input's value:If you want to insert material icons, you can use a
div
withcontenteditable
and insert a<span class="material-icons">[icon-name]</span>
after the user typed a comma:The bad thing about this is, that for example every house icon is five characters long, because we use
house
in the span and that is a house icon in the google material icons font, but it still remains five characters long. But this could be solved using another icon font, that works with classes.