的jQuery:jQuery的:更改圖片src和一流的onclick
$(".upvote").click(function() {
var id = $(this).attr('id');
var changeImage = ($(this).children('img').attr('src') === siteUrl + '/images/icon-upvote.png')
? siteUrl + '/images/icon-upvote-inactive.png'
: siteUrl + '/images/icon-upvote.png';
$(this).children('img').attr('src', changeImage);
var changeClass = ($(this).children('img').attr('src') === siteUrl + '/images/icon-upvote.png')
? 'vote-icon'
: 'vote-icon semi-transparent-more';
$(this).children('img').attr('class', changeClass);
$.ajax({
type: 'GET',
data: 'comic=' + id + '&type=upvote',
url: siteUrl + '/vote.php',
success: function() {
// PHP does all checks
}
});
});
HTML:
<div>
<a href="vote.php?comic=$fileName&type=upvote" id="$fileName" class="upvote$guestLink" onclick="return false;">$upvoteImage</a>
</div>
<div style="margin: 5px 0 8px 0;">
<span class="score$scoreStyle bold" id="$fileName">$fileScore</span>
</div>
<div>
<a href="vote.php?comic=$fileName&type=downvote" class="downvote$guestLink">$downvoteImage</a>
</div>
這是我已經有了和它的作品真的很好。問題是我知道有一種方法可以讓我的效率比我的效率高一點。
另外,如何選擇該跨度以更改其值?我將如何根據目前設置的內容調整價值?我一直在這個問題上苦苦掙扎,時間最長。
我建議你在帖子的開頭寫下你的問題。在知道要尋找什麼之前,必須通讀30行代碼才能讓某些人失望。 – 2012-01-01 01:58:10