天天看點

bootstrap-tagsinput.js 中的坑

這個插件差點把我氣死

各種問題。

注意是用input還是select

​​http://bootstrap-tagsinput.github.io/bootstrap-tagsinput/examples/​​

比如我在頁面加載完成就給input指派,使之顯示出來的時候就帶有一個tag,然後還可以自由地增減tag,但官方demo實在是坑。

浪費很多時間,罵了半天娘。

經過多次嘗試,才發現一些問題。

<input type="text" value="Amsterdam,Washington,Sydney,Beijing,Cairo" data-role="tagsinput"       
<select multiple data-role="tagsinput">
  <option value="Amsterdam">Amsterdam</option>
  <option value="Washington">Washington</option>
  <option value="Sydney">Sydney</option>
  <option value="Beijing">Beijing</option>
  <option value=      
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Bootstrap Tags Input</title>
    <meta name="robots" content="index, follow">
    <link rel="stylesheet" href="./Bootstrap Tags Input_files/bootstrap.min.css">
    <link rel="stylesheet" href="./Bootstrap Tags Input_files/bootstrap-theme.min.css">
    <link rel="stylesheet" href="./Bootstrap Tags Input_files/bootstrap-tagsinput.css">
</head>
<body>
    <div class="container">
        <select multiple data-role="tagsinput"></select>
    </div>

    <script src="./Bootstrap Tags Input_files/jquery.min.js"></script>
    <script src="./Bootstrap Tags Input_files/bootstrap.min.js"></script>
    <script src="./Bootstrap Tags Input_files/bootstrap-tagsinput.min.js"></script>
    <script>
        $(function () {
            $('select').tagsinput('add', 'some tag');
            $('select').tagsinput('add', 'some tassssg');
            $('select').tagsinput('add', 'some tass22ssg');
            $('select').tagsinput('add', 'some tass5555ssg');
            $('select').tagsinput('add', 'some tas3334sssg');
        });
    </script>
</body>
</html>