我正在尝试在用户单击某个按钮后将其禁用。我有这个功能很好的工作,但现在的表格将不会提交…下面是我的javascript:
<script>
$('.button').on('click', function(event) {
$(this).prop('disabled', true);
});
</script>
这又一次很好地禁用了该按钮,但现在我的表单将不会提交。这是一个众所周知的问题吗?
发布于 2018-06-06 05:04:45
在form submit
和disabled
按钮阻止提交之前发生Click
事件。这是解决方法:
<script>
$('.button').on('click', function(event) {
$this=$(this);
setTimeout(function(){$this.prop('disabled', true);},50);
});
</script>
另一种解决方法是处理$('form').on('submit',function(){...});
编辑:...INSTEAD。
发布于 2018-06-06 04:59:28
不是把它放在click
处理程序中,而是放在表单的submit
处理程序中。
$('form').on('submit', function(event) {
$(this).find(".button").prop('disabled', true);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
<button class="button">Submit</button>
</form>
发布于 2018-06-06 04:52:33
<script>
$('.button').on('click', function(event) {
$(this).prop('disabled', true);
$(this).parents('form').submit();
});
</script>
https://stackoverflow.com/questions/50708687
复制相似问题