2013-05-20 27 views
0

我想插入這些特定的標籤到數據庫中。這是我的HTML:如何使用jQuery的HTML和PHP插入標籤到數據庫

<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。我希望能夠存儲標籤,以便我可以使用它們來創建標籤雲。我怎樣才能做到這一點?

+1

你有沒有考慮過使用http://ivaynberg.github.io/select2/#tags或http://aehlke.github .io/tag-it /? – tftd

+0

nope lemme檢查出來 – 1baga

+0

首先嚐試'select2',因爲它完全可以做所有事情。圖形用戶界面非常棒,標籤存儲在附加'select2'的'input'中。所以,當你提交表單時,你只需要用php處理'input' - 類似'$ tags = explode(',',$ _POST ['tags']); foreach($ tags as $ tag){//做一些動作}' – tftd

回答

相關問題