How to display the pre-selected tags in the tag container from the tag
container?
I am working on a tag system, these tags have some specific colors. I want
to add the pre-selected tags to the tagcontainer from the database, but it
does not work.
mysql_result($result,0,"group_tag"):
<span class="label label-success">Male</span>,<span class="label
label-success">Female</span>
For more information, you can also go to my previous question:
Pass the information of tags to the php and display in another page( and
can also update in another page)?
and the jsfiddle is http://jsfiddle.net/V9Euk/1015/
Here is the javascript code:
$(function(){
tags = new Array(<?php echo explode(',',
mysql_result($result,0,"group_tag")); ?>);
$('#edit_button').click(function(){
$("#tag_handler").append(tags);
});/*displays the tags already exists*/
function add_tag(that){
var tag = $(that).text();
if($.inArray(tag, tags)>=0|| tags.length >= 10) return;
tags.push(tag);
var singleValues = $(that).find('span').clone();
singleValues[0].innerHTML += "×";
$("#tag_handler").append(singleValues);/*display the selected tags
in the tag_handler with × style*/
}
$(".fly li").click(function(){
add_tag(this);
});/*add tags to the tag_container when click the li*/
$('#tag_handler').on('click', 'span', function(){
var tag = $(this).text();
var index = $.inArray(tag, tags);
tags.splice(index,1);
$(this).remove();
});/*remove the tag when click this tag in the tag_container*/
$('input#tags_selected').val(tags);
});
No comments:
Post a Comment