代码之家  ›  专栏  ›  技术社区  ›  Simone Carletti

禁用按钮时,jQuery脚本在safari中不起作用

  •  1
  • Simone Carletti  · 技术社区  · 16 年前

    我编写了这段简单的代码,以防止表单被提交多次。

    jQuery.fn.preventDoubleSubmit = function() {
    
      this.find(":submit").each(function() {
        $(this).click(function() {
          this.originalValue = this.value;
          this.disabled = true;
          this.beenClicked = true;
        });
      });
    
      // [...]
    
      return this.submit(function() {
        if (this.beenSubmitted) {
          return false;
        } else {
          this.beenSubmitted = true;
        }
      });
    
    };
    
    // [...]
    

    不幸的是,Safari不起作用。当我单击表单时,按钮被禁用,Safari不会提交表单。

    知道吗?

    1 回复  |  直到 16 年前
        1
  •  2
  •   geowa4    16 年前

    $(".selector").submit(window.mySubmitHandler);
    
    function mySubmitHandler(evt) {
        $("#submitButton").attr("disabled", true);
        //do other stuff here if you want
    
        //redefine the function in the function itself
        window.mySubmitHandler = function(evt) {
            evt.preventDefault();
        }
    
        return true;
    }