php - 如何使用 jquery html 和 php 将标签插入数据库

标签 php javascript jquery html mysql

我想将这些特定标签插入数据库。这是我的 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 上的方式一样。我希望能够存储标签,以便我可以使用它们创建标签云。我怎样才能做到这一点?

最佳答案

你必须通过 jquery 执行 ajax 请求。

您可以在网上找到很多关于如何执行此操作的教程(例如 http://www.ibm.com/developerworks/opensource/library/os-php-jquery-ajax/ )

关于php - 如何使用 jquery html 和 php 将标签插入数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16658592/

相关文章:

javascript - 如何将具有相同类名的多个id值作为数组发送到ajax到codeigniter中的数据库?

javascript - Angular 用户界面选择不起作用

javascript - setTimeout 中的匿名函数不起作用

php - DEFINER =`coinstourb_admin` @`localhost` *//

php - 如何通过id查询数据库中的所有条目?

php - 如何在Where中使用别名

javascript - 如何创建可从每个文件夹访问的 cookie

JavaScript 对象 : What am i doing wrong here?

php - 更新现有的列属性 - Laravel 5 迁移

javascript - 平滑滚动到顶部不起作用