我正在使用这个 jQuery 将点击事件绑定到<a>
标签
jQuery(document).ready(function() {
jQuery(".post-like a").click(function(){
heart = jQuery(this);
// Retrieve post ID from data attribute
post_id = heart.data("post_id");
// Ajax call
jQuery.ajax({
type: "post",
url: ajax_var.url,
data: "action=post-like&nonce="+ajax_var.nonce+"&post_like=&post_id="+post_id,
success: function(count){
// If vote successful
if(count != "already")
{
heart.addClass("voted");
heart.siblings(".count").text(count);
}
}
});
return false;
})
})
呈现的 HTML 看起来像这样
<p class="button button_purple ico-like post-like"><a href="#" data-post_id="208" class="likelink"><span class="icon">
<span title="I like this article" class="qtip like"></span></span></a><span class="count">Vote</span></p>
与<span class="count">Vote</span>
a 标签重叠,我需要像这样保留 HTML。单击 a 标签或 span 时,如何让上面的 jQuery 触发?
这是生成 HTML 的 php
$output = '<p class="button button_purple ico-like post-like">';
if(hasAlreadyVoted($post_id))
$output .= '<span class="icon"><span title="'.__('I like this article', $themename).'" class="like alreadyvoted"></span></span><span class="count">'.$vote_count.'</span>';
else
$output .= '<a href="#" data-post_id="'.$post_id.'" class="likelink"><span class="icon">
<span title="'.__('I like this article', $themename).'" class="qtip like"></span></span></a><span class="count">'."Vote".'</span></p>';
return $output;
谢谢