【发布时间】:2018-06-30 03:22:33
【问题描述】:
这个想法是使用一个按钮来更改文本并在提交时禁用自身:
$(document).ready(function() {
$(".autobutton").click(function(event) {
// Show a spinner
var nv = $(this).html();
var nv2 = '<span class="fa fa-circle-o-notch fa-spin" aria-hidden="true"></span> ' + nv;
$(this).html(nv2);
var form = $(this).parents('form:first');
form.submit();
$(this).prop('disabled', true);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form action="test.php">
<button class="autobutton">Submit</button>
</form>
如果按钮是按钮类型提交,除非我删除禁用的属性集,否则不会提交表单。如果按钮是 type="button",则什么也不会发生。
【问题讨论】:
-
表格应该在哪里提交?在这种情况下到哪个位置说http?您缺少操作属性
-
实际的表格确实有动作等。为简单起见,我没有在这里提供完整的表格。
-
按钮类型必须设置为
submit...您必须执行<button type='submit'>click me</button>之类的操作 -
@Ahmad 按钮的类型默认为提交。
-
@Ahmad 他正在调用表单的
submit函数。输入的类型无关紧要。
标签: javascript jquery forms