确认取消后如何防止进一步的 jquery 脚本

how to prevent further jquery script after confirm-cancel

我有一个脚本可以在单击 link 时打开一个确认框:

html :

<a href="validation/object_1/" class="validation">Validate</a>
<a href="validation/object_2/" class="validation">Validate</a>

jquery

$('.validation').on('click', function() {
  return confirm('Are you sure tou want to validate this ' + $(this).attr('href').split("/")[1] + ' ?');
});

我有另一个 jquery 加载等待动画的脚本(一个相当复杂的脚本,我自己没有编写代码并且包含在我的内容管理系统应用程序中)

当我点击 link 时,确认弹出窗口打开,当我点击“取消”时,我不希望等待动画是 运行。

单击“取消”后,如何防止任何其他 jquery 脚本成为 运行?

编辑:这是完整的脚本,带有加载动画:

    (function($) {
        
        $('.validation').on('click', function() {
  return confirm('Are you sure tou want to validate this ' + $(this).attr('href').split("/")[1] + ' ?');
});
    
    /**
       * Represents the loading animation.
       */
      Loadinganimation = function(context, settings) {
        this.settings = settings;
        this._init = function(context) {
          // Exclude subselectors.
          if (settings.subselector != '') {
            var subselectorSuffix = ' ' + settings.subselector;
          } else {
            var subselectorSuffix = '';
          }
          // Show on href click!
          if (Drupal.settings.jquery_loadinganimation.show_on_href) {
            // Exclude some further cases that shell not trigger.
            $(context)
                .find("a[href]" + settings.subselector)
                .not('a[href*="javascript:"]')
                .not('a[href^="#"]')
                //.not('a[target="_blank"]')
                .not(".validation")
            .not('a[href^="http://fakepath"]')
                .not(".noLoadingAnimation")
            .not(".views-submit-button")
                .each(
                    function(i, element) {
                      // Only trigger links that have no js events registered.
                      if (typeof $(this).data("events") == 'undefined'
                          || jQuery.isEmptyObject($(this).data("events"))) {
                        $(this)
                            .click(
                                function(eventObject) {
                                  // Nicht bei Öffnen in neuem Tab (Strg+Klick)
                                  if (!eventObject.ctrlKey) {
                                    Drupal.behaviors.jquery_loadinganimation.Loadinganimation
                                        .show();
                                  }
                                });
                      }
                    });
          }
    
          // Show on form submit
          if (Drupal.settings.jquery_loadinganimation.show_on_form_submit) {
            // Only execute if no other js events are registered to prevent cases
            // where page is not being reloaded and layer does not close though.
            $(context).find("form" + subselectorSuffix).not(".noLoadingAnimation").not(".views-submit-button").not(".validation").submit(function() {
              Drupal.behaviors.jquery_loadinganimation.Loadinganimation.show();
              $(context).ajaxStop(function() {
                // Hide loading animation after ALL ajax events have finished
                Drupal.behaviors.jquery_loadinganimation.Loadinganimation.hide();
              });
            });
          }
    
          // Show on AJAX
          if (context == document) {
            // Global context!
            if (Drupal.settings.jquery_loadinganimation.show_on_ajax) {
              // Register loading animations for ajax events!
              $(context).ajaxStart(function() {
                // Show loading animation on request.
                Drupal.behaviors.jquery_loadinganimation.Loadinganimation.show();
              });
    
              $(context).ajaxStop(function() {
                // Hide loading animation after finish.
                Drupal.behaviors.jquery_loadinganimation.Loadinganimation.hide();
              });
            }
          }
    
          // Hide on animation click!
          if (Drupal.settings.jquery_loadinganimation.close_on_click) {
            $("div#loadinganimation").on('click', function() {
              Drupal.behaviors.jquery_loadinganimation.Loadinganimation.hide();
            });
          }
    
          // Hide on ESC press.
          if (Drupal.settings.jquery_loadinganimation.close_on_esc) {
            $(document).keyup(function(event) {
              var keycode = event.which;
              if (keycode == 27) { // escape, close box
                Drupal.behaviors.jquery_loadinganimation.Loadinganimation.hide();
              }
            });
          }
        };
    
        // Initialize!
        this._init(context);
    
        // Register global Drupal.behaviors.jquery_loadinganimation.Loadinganimation
        // object after init!
        Drupal.behaviors.jquery_loadinganimation.Loadinganimation = this;
    
        /**
         * Displays the loading animation.
         */
        this.show = function() {
          // Only show if not already shown.
          if ($("div#loadinganimation").length == 0) {
            $("body")
                .append(
                    '<div id="loadinganimation"><div class="loadinganimation-box"><div class="loadinganimation-outer"><div class="loadinganimation-inner">&nbsp;</div></div><span class="loading-text">'+ Drupal.t('Merci de patienter ...', {}, {context: "jquery_loadinganimation"}) +'</span></div></div>');
          }
        };
    
        /**
         * Hides the loading animation.
         */
        this.hide = function() {
          $("div#loadinganimation").remove();
        };
      };
    
      /**
       * Initialization
       */
      Drupal.behaviors.jquery_loadinganimation = {
        /**
         * Run Drupal module JS initialization.
         *
         * @param context
         * @param settings
         */
        attach : function(context, settings) {
          // Initialize general loading animation.
          Drupal.behaviors.jquery_loadinganimation.Loadinganimation = new Loadinganimation(
              context, settings.jquery_loadinganimation);
        }
      };
      
      
    })(jQuery);

像这样。并将 'tou' 更改为 'you'.

$('.validation').on('click', function() {
  if (confirm('Are you sure you want to validate this ' + $(this).attr('href').split("/")[1] + ' ?'))
     {
       //Do your validation only if the user clicks okay.
     }else 
     {
       //If you have to manually turn off your animation do it here.  
     };
});