我想将这些特定标签插入数据库。这是我的 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/