简体   繁体   English

Select2始终显示占位符

[英]Select2 Always show placeholder

I am using a select2 component for selection. 我正在使用select2组件进行选择。

I fiddled an example together here: https://fiddle.jshell.net/mmo2dqno/15/ 我在这里一起摆了一个例子: https : //fiddle.jshell.net/mmo2dqno/15/

What I am trying to do is: 我正在尝试做的是:

  • Select an item via the select2 widget 通过select2小部件选择一个项目
  • Show that item in the div below 在下面的div中显示该项目
  • Dont show the label in the search box. 不要在搜索框中显示标签。

This works fine. 这很好。 The problem is, that when one item is selected, the searchbox isn't showing the placeholder attribute anymore. 问题是,当选择一项时,搜索框不再显示占位符属性。

How can I tell the browser to assume the input as empty and show the placeholder again? 如何告诉浏览器将输入假定为空并再次显示占位符?

You could kill the select2 plugin with JS, and then load it again. 您可以使用JS杀死select2插件,然后再次加载它。 Or you could use Js to choose an disabled placeholder option. 或者,您可以使用Js选择禁用的占位符选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM