标签javascript设置最大值

时间:2017-06-21 23:09:18

标签: javascript html css

我有一个JavaScript我想将最大标签选项添加为仅6并且没有重复这是我到目前为止的代码

src/timeline.js

Demo

1 个答案:

答案 0 :(得分:0)

我使用Select2执行此操作:

  • 使用标记样式。
  • 不重复。
  • 最多3个选项。

<强>代码:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>Hello</title>
    <script src="https://code.jquery.com/jquery-2.2.4.js"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.full.min.js"></script>
    <script>
      $(function () {
        $(".select2").select2({
          maximumSelectionLength: 3,
          width: 350
        });
      });
    </script>
  </head>
  <body>
    <select name="tags" id="tags" class="select2" multiple="multiple">
      <option value="PHP">PHP</option>
      <option value="CSS">CSS</option>
      <option value="CPP">C++</option>
      <option value="JavaScript">JavaScript</option>
    </select>
  </body>
</html>

<强>段

$(function () {
  $(".select2").select2({
    maximumSelectionLength: 3,
    width: 350
  });
});
<script src="https://code.jquery.com/jquery-2.2.4.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.full.min.js"></script>
<select name="tags" id="tags" class="select2" multiple="multiple">
  <option value="PHP">PHP</option>
  <option value="CSS">CSS</option>
  <option value="CPP">C++</option>
  <option value="JavaScript">JavaScript</option>
</select>

演示: JSBin