如何在文本框中显示从下拉列表中选择的多个项目?

时间:2018-08-10 04:51:06

标签: javascript

如何在文本框中显示从组合框中选择的多个项目?我需要用JavaScript编写代码。

1 个答案:

答案 0 :(得分:0)

您的意思是这样吗?

$(document).ready(function() {
    $('.js-example-basic-multiple').select2();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/css/select2.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/js/select2.min.js"></script>
<select class="js-example-basic-multiple" name="states[]" multiple="multiple">
  <option value="C1">Content1</option>
  <option value="C2">Content2</option>
  <option value="C3">Content3</option>
  <option value="C4">Content4</option>
  <option value="C5">Content5</option>
  <option value="C6">Content6</option>
  <option value="C7">Content7</option>
  <option value="C8">Content8</option>
  <option value="C9">Content9</option>
</select>