First and Second touch a button,如何显示不同时间的图像?

First and Second touch of a button, how to show images at different times?

我想在触摸按钮后更改图像的 css,我想在第二次触摸按钮后更改另一图像的 css。

如何将此代码合并到 1 个函数中?因为现在当我触摸按钮时,它会同时显示 2 个图像。

$('.button').on('touchend', function(){
   $('img.image1').css('visibility', 'visible');
});

$('.button').on('touchend', function(){
   $('img.image2').css('visibility', 'visible');
});

将首先打开 img 1,然后在第二次单击时打开 img 2。这也不会隐藏,只是先将 css 添加到 img 1,然后在第二次单击时添加 css到 img 2.

$('.button').on('touchend', function(){
   if($('img.image1').css('visibility') == 'visible')
   {
     $('img.image2').css('visibility', 'visible');
   }
   else
   {
     $('img.image1').css('visibility', 'visible');
   }
});

这样的事情怎么样?你只需要一个标志来知道按钮被按下或触摸了多少次。

var timeTouched = 0;

$('.button').on('touchend', function(){
   if (timeTouched == 0){
      $('img.image1').css('visibility', 'visible');
   }
   else {
      $('img.image2').css('visibility', 'visible');
   }
   timeTouched++;
});

您想使用标志或类似的东西在每次单击时更改按钮绑定。

var action = 1;
$("input").on("click", viewSomething);

function viewSomething() {
    if ( action == 1 ) {
        $("body").css("background", "honeydew");
        action = 2;
    } else {
        $("body").css("background", "beige");
        action = 1;
    }
}