$(function(){
$('.tagbox').click(function(){
$("input[name='tag']").focus();
})
$(document).on("click", "#tags span", function(){
$(this).remove();
});
$('.old span').click(function(){
ids=new Array();
var txt=$(this).attr('name');
var id=$(this).attr('id')
$('#tags .tag').each(function(){
ids+=$(this).attr('id')+','
});
if(ids==''){
ids=new Array();
}else{
ids = ids.split(",");
}
if(ids.length>5){
alert('标签最多添加5个哦!');
return false;
};
var exist=$.inArray(id,ids);
if(exist<0){
$('#tags').append(''+txt+'')
}
})
$("input[name='tag']").bind('keyup',function(event){
if(event.keyCode==13){
var txt=$(this).val();
if(txt!=''){
txts=new Array();
$('#tags .tag').each(function(){
txts+=$(this).attr('name')+','
});
if(txts==''){
txts=new Array();
}else{
txts = txts.split(",");
}
if(txts.length>5){
alert('标签最多添加5个哦!');
return false;
};
var exist=$.inArray(txt,txts);
if(exist<0){
$('#tags').append(''+txt+'')
$(this).val('');
}else{
$(this).val('');
}
}
}
});
})
|