如何使用jquery html和php在数据库中插入标签
How to insert tags into database using jquery html and php
我想把这些特殊的标记插入数据库。这是我的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/)
相关文章:
- javascript:将数据库中的数据插入到html5文本字段中
- 从数据库中获取数据并插入JavaScript变量
- 使用JavaScript插入Access数据库
- 使用formData使用ajax将图像插入数据库
- 如何优化循环以插入到数据库中
- PHP 数组未向数据库插入多行
- PHP动态数据库插入
- HTML5本地数据库插入
- 从多选表数据库插入数据到单行表数据库
- 数据库插入图像而不是文本
- 向数据库插入文件名
- AngularJS向数据库插入数据两次
- 当向数据库插入大量记录时,我应该如何编写节点脚本以最小化内存使用
- 当用户向数据库插入一行时如何刷新页面
- 当我们试图关闭浏览时,向数据库插入数据
- NodeJS+Express+Mongoose(MongoDB)数据库插入错误
- 流星在数据库插入前检查文本
- 如何更新页面后,数据库插入或更新在PHP或ajax
- 如何向SQL数据库插入动态值
- 奇怪的数据库插入问题在Phonegap和SQLite