【问题标题】:Bootstrap Tags: how to retrieve items from the input list to server side?引导标签:如何从输入列表中检索项目到服务器端?
【发布时间】:2015-07-28 11:34:29
【问题描述】:

我目前正在使用以下库: Bootstrap Tags

用户界面运行良好。 但是我对如何检索输入框中的所有值感到困惑? (我想要用户输入的整个标签列表)并将该信息发送到服务器端。 (首先我想使用 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>

【问题讨论】:

  • 没有这样的功能:$("input").tagsinput
  • 我们需要看到更多的分配来调试它。请包含一个链接或您的完整 HTML 页面。我认为这与在执行该代码或根本不包含该代码之后包含的 tagsinput 插件有关。
  • 在表单提交时,我如何获取用户输入的内容? (在我包含 taginput 输入字段之后)

标签: javascript php twitter-bootstrap


【解决方案1】:

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

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

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

您可以通过jQuery serialize()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-06-09
    • 2019-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多