嗨,我是拍圖片的競爭頁(使用不同的規則)jQuery的多對多關係
我似乎無法環繞這個「問題」
規則我的頭是:用戶可以投票給一張圖片,但不是他自己的。 他能夠取消他的投票,並投票給另一個投票。
我有PHP來檢查所有的,它工作正常。
類型爲0的這種情況下
function addVote(pictureID, competitionID, type){
$.post('vote.php', {pictureID:pictureID, competitionID:competitionID, vote:1}, function(data){
if (data == 'success') {
$("#comp_voteButton_"+pictureID).text('Remove vote');
$("#comp_voteButton_"+pictureID).addClass("alreadyVoted");
$("#comp_voteButton_"+pictureID).attr("onclick", "remVote(" + pictureID + ", " + competitionID + ")")
if (type == 0){
$('.button:not(.disabled, #comp_voteButton_'+pictureID+')').text('Only one vote permitted');
$('.button:not(.disabled, #comp_voteButton_'+pictureID+')').removeClass('alreadyVoted');
$('.button:not(.disabled)').addClass('.disabled, .red');
getVote(pictureID, competitionID);
}else {
$().toastmessage('showErrorToast', "Error!");
}
});
}
在同一個文件:
function remVote(pictureID, competitionID){
$.post('vote.php', {pictureID:pictureID, competitionID:competitionID, vote:0}, function(data){
if (data == 'success') {
$("#comp_voteButton_"+pictureID).text('Vote picture');
$("#comp_voteButton_"+pictureID).attr("onclick", "addVote(" + pictureID +","+competitionID+","+0+")")
$("#comp_voteButton_"+pictureID).removeClass('alreadyVoted');
getVote(pictureID, competitionID);
}else {
$().toastmessage('showErrorToast', "Error!");
}
});
}
編輯: 這裏的鏈接,如果這使得它更容易:
<a href="javascript:void(0);" class="button blue small" id="comp_voteButton_<?echo $row['ID']?>" onclick="addVote(<?echo $row['ID']?>, <?echo $id?>, <?echo $vote?>)">Vote</a>
我想要的:在addVote上,所有其他按鈕都應該設置爲'onclick(remVote(ID,compID))' - 但我不能這樣做,因爲這兩個ID都沒有輸入到addVote函數中。
我希望你們得到我的問題(也許這是不可能的,或者一個奇怪的解決方法必須作出) - 但也許有一個漂亮的做法。
因此,您想要設置所有圖片的onclicks以刪除當前選定的投票的問題? – Lincoded
是(這是很簡單的) - 但最困難的部分是,當用戶再點擊按鈕(在另一張照片,應該投票支持圖片,並刪除舊的).. – Pzoco