2014-02-11 38 views
0

有一段时间我一直在使用下面的代码...隐藏表单提交按钮与jQuery只有当实际提交

$("input[type=submit]:not(.noHide)").one('click', function() { 
    $(this).hide(); 
    $(this).click(function() { return false; }); 
}); 

禁用表单提交按钮上点击,主要是为了避免双重点击提交两次。

我现在有一个表格或两个必需的字段...

<input type="date" name="DatePurchased" required> 

而这种断裂,因为提交按钮,一旦遗漏修正现在已经没有了。

有没有办法在成功提交之后禁用按钮,而不仅仅是点击?

+1

在隐藏/禁用它之前检查验证错误。 – Krishna

+0

http://stackoverflow.com/questions/11534690/how-to-do-a-jquery-callback-after-form-submit – miny1997

+0

使用错误的事件处理程序进行表单提交处理的另一个副作用。 –

回答

1

改为使用submit-event。

$("input[type=submit]:not(.noHide)").on('submit', function() { 
    if ($(this).not(':visible')) { 
     return false; 
    } 
    $(this).hide(); 
}); 
+0

这似乎并没有隐藏按钮。 – Jay2001

+0

似乎提交事件只能附加到表单,而不是提交按钮。 – Jay2001

+0

没错。对不起,我忘了提到这一点。 –