0
У меня есть этот код ниже:Append Количество вара после HTML (сердце вара) - JQuery
heart.html("<i class='glyphicon glyphicon-remove-sign'></i>   "+count);
я хочу счетчик элементов вне heart.html(). что-то вроде:
heart.html("<i class='glyphicon glyphicon-remove-sign'></i>   ")+count;
сердце - это умение, которое можно щелкнуть, и я не хочу, чтобы граф был доступен для клика.
весь код:
jQuery(document).ready(function()
{
jQuery('body').on('click','.jm-post-like',function(event)
{
event.preventDefault();
heart = jQuery(this);
post_id = heart.data("post_id");
heart.html("<i class='glyphicon glyphicon-cog'></i>");
jQuery.ajax
({
type: "post",
url: ajax_var.url,
data: "action=jm-post-like&nonce="+ajax_var.nonce+"&jm_post_like=&post_id="+post_id,
success: function(count)
{
if(count.indexOf("already") !== -1)
{
var lecount = count.replace("already","");
if (lecount === "0")
{
lecount = "0";
}
heart.prop('title', 'Like');
heart.removeClass("liked");
heart.html("<i class='glyphicon glyphicon-heart'></i>   "+lecount);
}
else
{
heart.prop('title', 'Unlike');
heart.addClass("liked");
heart.html("<i class='glyphicon glyphicon-remove-sign'></i>   "+count);
}
}
});
});
});
function getPostLikeLink($post_id)
{
$like_count = get_post_meta($post_id, "_post_like_count", true); // Get post likes.
$count = (empty($like_count) || $like_count == "0") ? '0' : esc_attr($like_count);
if (AlreadyLiked($post_id))
{
$class = esc_attr(' liked');
$title = esc_attr('Unlike');
$heart = '<i class="glyphicon glyphicon-remove-sign"></i>   ';
}
else
{
$class = esc_attr('');
$title = esc_attr('Like');
$heart = '<i class="glyphicon glyphicon-heart"></i>   ';
}
$output = '<a href="#" class="jm-post-like'.$class.'" data-post_id="'.$post_id.'" title="'.$title.'">'.$heart.' </a>'.$count;
return $output;
}
Любая помощь будет оценена.
спасибо за помощь. Я просто попробовал это. счет не отображается. Я снова проверяю свой код, чтобы узнать, что вызывает проблему. – user3266957
@ user3266957 если вы попробовали второй метод, в нем было несколько проблем ... теперь обновлено ... также см. [Первый метод] (http://jsfiddle.net/arunpjohny/chobju1r/3/) и [второй метод ] (http://jsfiddle.net/arunpjohny/chobju1r/6/) –
yup спасибо. – user3266957