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>

版本信息
jQuery v2.1.4
Bootstrap v3.3.5 (http://getbootstrap.com)
bootstrap-tagsinput v0.8.0

发布了177 篇原创文章 · 获赞 47 · 访问量 43万+

猜你喜欢

转载自blog.csdn.net/festone000/article/details/91967406