如何使用jquery html和php将标签插入数据库 [英] How to insert tags into database using jquery html and php

查看:101
本文介绍了如何使用jquery html和php将标签插入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to insert these particular tags into the database. This is my 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上的方式一样。我希望能够存储标签,以便我可以使用它们来创建标签云。我怎样才能做到这一点?

What the piece of code creates a tag when a user is creating a new post on my forum, just like the way it is here on StackOverflow. I want to be able to store the tags so that I can use them to create a tag cloud. How can I accomplish this?

推荐答案

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

you have to do an ajax request via jquery.

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

you can find a lot of tutorials on web how to do that (e.g. http://www.ibm.com/developerworks/opensource/library/os-php-jquery-ajax/)

这篇关于如何使用jquery html和php将标签插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆