最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Tagify set data in tagify input on click - Stack Overflow

programmeradmin3浏览0评论

I have a problem in tagify library, I need to set data in input type tagify on click some button, but not set, this is my code

        $(document).ready(function() {
        $('#getInfo').on('click', function () {
            $('#kt_tagify_1').val('tag name');
        })
    });

this is my library .md

I have a problem in tagify library, I need to set data in input type tagify on click some button, but not set, this is my code

        $(document).ready(function() {
        $('#getInfo').on('click', function () {
            $('#kt_tagify_1').val('tag name');
        })
    });

this is my library https://github./yairEO/tagify/blob/master/README.md

Share Improve this question edited Dec 16, 2019 at 13:28 RedOne asked Dec 16, 2019 at 13:19 RedOneRedOne 731 gold badge3 silver badges8 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

The demo:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3/1999/xhtml" xml:lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
  <title>Click Add Tag Demo</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr/npm/@yaireo/[email protected]/dist/tagify.css" />
  <script src="https://cdn.jsdelivr/npm/@yaireo/[email protected]/dist/tagify.min.js"></script>
  <script src="https://cdn.jsdelivr/npm/[email protected]/dist/jquery.min.js"></script>
</head>

<body>
  <input type="text" name='basic' value="tag1, tag2" />
  <button id="click">add tags</button>
  <script>
    var input = document.querySelector('input[name=basic]');

    var tagify = new Tagify(input);


    $("#click").on("click", function() {
      var n = "ADD_IT_" + Math.random();
      var tags = [];
      tags.push(n);
      tagify.addTags(tags);
    })
  </script>
</body>

</html>

You can find a methon on here https://github./yairEO/tagify#events

How to use:

发布评论

评论列表(0)

  1. 暂无评论