我一直在努力解决这个问题。我是HTML和Jquery的新手。想法是在多次点击后切换图像。我需要的只是一些建议和提示!
解决方案是IF声明!
var change = 1;
$('.checkOpdracht1').click(function(){
if (change++ % 6 == 0) {
GrowPlant(1);
}
});
$('.checkOpdracht2').click(function(){
if (change++ % 6 == 0) {
GrowPlant(2);
}
});
$('.checkOpdracht3').click(function(){
if (change++ % 6 == 0) {
GrowPlant(3);
}
});
$('.checkOpdracht4').click(function(){
if (change++ % 6 == 0) {
GrowPlant(4);
}
});
$('.checkOpdracht5').click(function(){
if (change++ % 6 == 0) {
GrowPlant(5);
}
});
$('.checkOpdracht6').click(function(){
if (change++ % 6 == 0) {
GrowPlant(6);
}
答案 0 :(得分:0)
试试这个:
var clickCount = 0;
$('#myEl').on('click', function() {
clickCount = parseInt($(this).data('count')) || 0;
clickCount++;
if (clickCount % 6 === 0) {
// Change background image
}
$(this).data('count', clickCount);
});
答案 1 :(得分:0)
做类似的事情,
var url = ["http://www.gettyimages.in/gi-resources/images/Homepage/Category-Creative/UK/UK_Creative_462809583.jpg", "https://www.ucl.ac.uk/news/news-articles/1213/muscle-fibres-heart.jpg"];
var index = 0;
var change = 1;
$("img").click(function() {
if (change++ % 6 == 0) {
$(this).attr("src", url[index++]);
}
});