dqqt31923 2014-06-18 13:37
浏览 123

如何使用tag-it jquery插件获取标签

I am using tag-it jquery plugin for my work. I want to get tags which i was entered in the text area but i got empty string. here is my code

<?
    $simple_tags = array('c++', 'java', 'php', 'coldfusion', 'javascript', 'asp', 'ruby', 'python', 'c', 'scala', 'groovy', 'haskell', 'perl', 'erlang', 'apl', 'cobol', 'go', 'lua');
?>
    <script>
        $(function(){
            var sampleTags = <?php echo json_encode($simple_tags); ?>; 
            $('#singleFieldTags').tagit({
                availableTags: sampleTags,
                // This will make Tag-it submit a single form value, as a comma-delimited field.
                singleField: true
            });
        });
        function show()
        {
            console.log($('#singleFieldTags').val());
        }
    </script>

<div id="wrapper"> 

    <div id="content">
        <form>
            <ul id="singleFieldTags"></ul>
            <input type="submit" value="Submit" onclick="show()">
        </form>
    </div>
</div>
  • 写回答

1条回答 默认 最新

  • duanmei1850 2014-07-10 11:32
    关注

    First of all I would say that you make the tags as string. Secondly use an input element rather than the ul in order to get the values.

    Your code would become something like the following.

    Remember to link it to your js function alert so that you could see the output value.

    Let me know if it works as I have worked with this plugin in the past.

    <?php 
    
        $simple_tags = "'c++', 'java', 'php', 'coldfusion', 'javascript', 'asp', 'ruby', 'python', 'c', 'scala', 'groovy', 'haskell', 'perl', 'erlang', 'apl', 'cobol', 'go', 'lua'";
    
    ?>    
    
    <script type="text/javascript">
       $(function(){
          var sampleTags = [<?php echo $simple_tags; ?>];
          $("#singleFieldTags").tagit({
              availableTags: sampleTags
        });
    });
    </script>
    
    <input type="text" id="singleFieldTags"/>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据