$(".useful").click(function(){ var oldValue=parseInt($(this).html());//取出现在的值,并使用parseInt转为int类型数据 if($(this).hasClass("hasadd")){ alert("已经点过啦"); return false; }else{ oldValue++;//自加1 $(this).html(oldValue); $(this).addClass("hasadd");//将增加后的值付给原控件 } }); |