2017-12-27 13 views
-1

私は自分のコード内の別の関数の実行を停止したい、私のJSコードは次のようになります。jQueryは他の関数の実行を停止しますか?

私はすでに試した何
<script> 
    $(document).ready(function() { 

     <?php if ($saveMethod) : ?> 
     $("#running").html('<b>Save</b>'); 
     <?php else : ?> 
     $("#running").html('<b>Skip</b>'); 
     <?php endif; ?> 

     $("#running").click(function() { 
      // tried to stop customRedirect(); 
      return false; 
     }); 

     <?php if ($redirectURL != '') : ?> 
     customRedirect (10, "timer", "<?= $redirectURL ?>"); 
     <?php endif; ?> 
    }); 
</script> 

$("#running").click(function() { 
    // tried to stop customRedirect(); 
    return false; 
}); 

私は、ユーザーがクリックした場合customRedirectの実行を停止したいです#runningにあります。

+0

PHPタグはどこですか? –

+0

私はあなたが欲しいものを理解していません。 –

+0

@ MiquelAl.Vicensユーザーが$( "#running")をクリックした後、customRedirect()の実行を停止したいとします。 –

答えて

0

私は多分あなたは、その関数にこれを実装することができますが、我々はそれはもう起こらしたくないときに我々はそれをクリアすることができるようにトリックが変数にsetTimeoutを割り当てているあなたのcustomRedirectを知らない:

let delayedRedirect = setTimeout(function(){ 
     window.location = '<?= $redirectURL ?>'; 
     // or your customRedirect() if you have anything fancy 
    }, 10 *1000); 


$("#running").html('<b><?=$saveMethod? "Save" : "Skip" ?></b>'); 
$("#running").click(function() { 
    clearTimeout(delayedRedirect); 
});