【问题标题】:How to insert tags into database using jquery html and php如何使用 jquery html 和 php 将标签插入数据库
【发布时间】:2013-05-15 13:07:07
【问题描述】:

我想将这些特定标签插入数据库。这是我的 HTML:

<div id="tags">
    <input type='text' name='tags' placeholder='Type in topic tags here seperated by commas' id="tagg" />
</div>

和 jQuery 部分:

 counter = 0;
    $(function(){
        $('#tags input').on('focusout',function(){    
        var txt= $.trim( $(this).val() ).replace(',','');
        if(txt){
        $(this).before('<span class="tag"  name="tags[]" value="'+txt+'">'+txt+'</span>');
        counter++;
        if(counter==5){
            $('#tags input').prop('disabled', true);
        }
        //$(".bgtopic").append("<input type='hidden' name='tags[]' />")
        //Yet to implement the counter varibale to be visible...
    }

    $(this).prop('value','');  
  }).on('keyup',function( e ){
    if(e.which==188){
      $(this).focusout(); 
    }
  });

  $('#tags').on('click','.tag',function(){
     $(this).remove();
     counter--;
     $('#tags input').prop('disabled', false);

  });

});

当用户在我的论坛上创建新帖子时,这段代码会创建标签,就像在 StackOverflow 上一样。我希望能够存储标签,以便我可以使用它们来创建标签云。我怎样才能做到这一点?

【问题讨论】:

  • 不让我去看看
  • 先试试select2,因为它几乎可以做任何事情。 GUI 很棒,标签存储在您附加select2input 中。因此,当您提交表单时,您只需要使用 php 处理 input - 类似于 $tags = explode(',', $_POST['tags']); foreach($tags as $tag) { //do some action }

标签: php javascript jquery html mysql


【解决方案1】:

你必须通过 jquery 做一个 ajax 请求。

你可以在网上找到很多关于如何做到这一点的教程(例如http://www.ibm.com/developerworks/opensource/library/os-php-jquery-ajax/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-02-27
    • 1970-01-01
    • 1970-01-01
    • 2014-08-29
    • 1970-01-01
    • 2011-06-15
    相关资源
    最近更新 更多