0

.focus() を使用して、スライダーを次の画面に進めたいと思います。次へと戻るボタンがあります。ユーザーが次のボタンをクリックした場合、.focus() 関数でスライダーを進めたくありません。ただし、フォーカスが次のボタンにある場合は、フォーカスが次のボタン .click() 関数をトリガーするようにしたいと思います。

これが私が今持っている方法です。Tab キーを押して次のボタンにフォーカスを置くと、スライダーが進みます。次へボタンをクリックすると、スライダーが 2 回進みます。

$(".nextbutton4").focus(function() {
     $(".nextbutton4").click();
});

if-else ステートメントを使用して focus() 関数の別のバージョンを思いつきましたが、機能しません。

// This allows a tab advancement to trigger the next action
$(".nextbutton4").focus(function() {
    if (//This is where I would like to check whether the button was clicked) {
          alert('Next Button is Clicked');
          // Do Nothing
    }
    else {
          alert('Next Button Not Clicked');
          $(".nextbutton4").click();
     }  
});
4

1 に答える 1

1

ユーザーがリンクをクリックしたときにクラスを追加してみることができます。

$('.nextbutton4').click(function() { $(this).addClass('clicked'); });

次に、クラスがあるかどうかを確認します。

// This allows a tab advancement to trigger the next action
$(".nextbutton4").focus(function() 
{
    if ($(this).hasClass('clicked')) 
    {
          alert('Next Button is Clicked');
          // Do Nothing
    }
    else 
    {
          alert('Next Button Not Clicked');
          $(this).click();
     }  
});
于 2012-10-25T16:23:24.573 に答える