引导标签:如何从输入列表中检索条目到服务器端

Bootstrap Tags: how to retrieve items from the input list to server side?

本文关键字:检索 服务器端 列表 输入 标签      更新时间:2023-09-26

我目前正在使用以下库:引导标记

UI工作正常。但我感到困惑的是如何检索输入框内的所有值?(我想要用户输入的标签的整个列表),并将该信息发送到服务器端。(首先,我想使用javascript打印出来,然后使用post请求发送到服务器)

$("input").val()
$("input").tagsinput('items') //this is giving me error message
下面是我的代码:
 <!-- Textarea -->
                <div class="form-group">
                  <label class="col-md-3 control-label" for="textarea">Search Tags</label>
                  <div class="col-md-8">
                      <input class="form-control" id="tagTextarea" data-role="tagsinput" id="tagsInput" />
                  </div>
                </div>
                <script>
                    $('input').tagsinput({
                        trimValue: true
                    }
                    );
                    $('input').on('beforeItemAdd', function(event) {
                        // event.item: contains the item
                        // event.cancel: set to true to prevent the item getting added
                       //Now how do i retrieve those values inside?
                        console.log(tags);//<--how to print value?
                      });
                </script>

您可以使用jquery的serialize函数获取所有表单值

$('#formId').serialize();

您可以遍历该函数提供的结果以在客户端打印,并将相同的结果发送到服务器端代码。

可以通过jQuery serialize()