如何使用jquery html和php在数据库中插入标签

How to insert tags into database using jquery html and php

本文关键字:数据库 插入 标签 php 何使用 jquery html      更新时间:2023-09-26

我想把这些特殊的标记插入数据库。这是我的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/)