同一张照片上有两个按钮,1个用于删除,第二个用于顶部照片。当我点击顶部图标时,这个活动的所有元素,当我点击所选和上一个删除活动类的顶部图标更改类时,我想要。
如何在此功能上使用toggleClass。
echo "<div class=\"photo-cp\">";
echo "<a id=\"".$data['pid']."\" onclick=\"photo_top(this);\" class=\"top-photo\"></a>\n";
echo "<a id=\"".$data['pid']."\" onclick=\"photo_delete(this);\" class=\"remove-photo rounded\"></a>";
echo "</div>\n";
CSS
.photo-cp {position:absolute; top:5px; right:5px; width:42px; height:26px; display:block;}
.photo-cp a {float:left; margin:4px 0 0 4px;}
.remove-photo {background: url("../images/remove.png") no-repeat 0 0; width:16px; height:16px; display:block; cursor:pointer}
.top-photo {width:16px; height:16px; display:block; cursor:pointer}
.top-photo {background: url("../images/star.png") no-repeat 0 0;}
.top-photo.active { background: url("../images/star.png") no-repeat 0 -16px; }
Jquery的
function photo_top(obj){
var pid = obj.id;
$.ajax({
type: "POST",
url: "jq-photos.php",
data: { pid: pid },
dataType: "json",
beforeSend: function() {
},
success: function(obj) {
if (obj.error == false) {
$(".top-photo").toggleClass('active').sibling().removeClass('active');
} else {
alert("Error!");
}
}
});
return false;
}