duanao4503
2015-10-25 13:39 阅读 107

将代码嵌套在input元素中

I am looking for someone to guide me in the right direction.

I have an input form. I want to make it so when a user types in something such as 'landscaping', it checks a file(json), and if 'landscaping' is found, then it creates a small box inside the input form. Allowing users to stack multiple inline boxes. It would be something similar to this:

enter image description here

As I was posting the question, I realized that this website uses the exact function I'm looking for, so the best example is I'm looking to make something like the tag input form at the bottom of the post question page.

Thanks in advance!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    duanli4146 duanli4146 2015-10-25 13:43

    Select2 does that. You can view it's multiple select boxes example here.

    $(".js-example-basic-multiple").select2();
    
    <select class="js-example-basic-multiple" multiple="multiple">
      <option value="landscaping">Landscaping</option>
      ...
      etc. all options you need
    </select>
    

    so you can add all your data in the json file as options to the select box. Or if you see more of the examples, it can load the options from an array (Loading array data) or even from a remote file that returns JSON (Loading remote data).

    点赞 评论 复制链接分享

相关推荐