【发布时间】:2020-04-05 23:04:54
【问题描述】:
我正在尝试制作一个心形点击计数器,只允许单击一次,它会在以 1280 开头的数字上加 1。心形以无颜色开头,但单击时会切换为红色心.这是我尝试过的报价,但是当我单击心脏时,数字并没有增加。 :( :(
有人可以看看代码并说出哪一部分是错的吗?
$('body').on('click', '.share-icons a.heart24', function(event){
event.defaultPrevented;
console.log('heart');
function log_quote_heart(id, place, ac_type, t, pp, current_object){
// if(t === 't') return;
if($(current_object).hasClass('heart24-on')){
return;
}
var heartLink = $('.wrap-block[data-id="'+id+'"] a.heart24');
$(heartLink).removeClass('heart24-off').addClass('heart24-on');
heartLink.html(+heartLink.html()+1);
.heart24-on {
background: url(//www.azquotes.com/public2/images/heart24-on.png) no-repeat!important;
background-size: 24px auto!important;
border-radius: 0;
}
.heart24 a {
font-weight: 500;
color: #a94c1c;
}
.heart24 {text-decoration:none}
.heart24 {position:relative;top:0!important;display:inline-block;margin-right:4px;width:24px;height:24px;border-radius:50%}
.heart24 a{font-weight:500;color:#a94c1c}
.heart24-on{background:url(//www.azquotes.com/public2/images/heart24-on.png) no-repeat!important;background-size:24px auto!important;border-radius:0}
.heart24-off{background:url(//www.azquotes.com/public2/images/heart24-off.png) no-repeat!important;background-size:24px auto!important;border-radius:0}
.heart24{vertical-align:top;background-position-x:0;padding-left:31px;padding-top:2px;padding-bottom:0;line-height:20px;font-size:12px}
<a class="heart24 heart24-off" href="javascript:void(0);">1280</a>
【问题讨论】:
-
请查看我的答案。
-
如果对您有用,请勾选绿色选中答案。
-
感谢您的帮助埃尔曼。我刚刚打勾:)
标签: javascript jquery counter