由於代碼環境問題,我需要清理我的代碼。這個jquery太相似了。我怎樣才能解決這個問題?擺脫冗餘代碼?
var angle = 0;
$('.rotate-receipt').on('click', function() {
var index = $(this).data('button-index');
angle = (angle + 90)%360;
var className = 'rotate' + angle;
$('#receipt-image-'+index).removeClass().addClass(className);
});
$('.zoom-in').on('click', function() {
var index = $(this).data('button-index');
var image = $('#receipt-image-'+index);
image.width(image.width() + 100);
});
$('.zoom-out').on('click', function() {
var index = $(this).data('button-index');
var image = $('#receipt-image-'+index);
image.width(image.width() - 100);
});
});
這是這裏的主題。也許更多的話題在http://codereview.stackexchange.com/ - 可能重複http://stackoverflow.com/questions/10511897/assigning-more-than-one-class-for-one-event – mplungjan
@J。 Doe,將鏈接留在「CodeReview」上的問題上,我會幫你 – RomanPerekhrest
你的HTML樣本也會非常有用。 –