[英]Submit form with button only + disable on submit w/jQuery
我需要仅在单击按钮后才能提交表单。 提交表单后,我还需要禁用按钮。
我当时正在考虑向按钮添加ID并添加点击功能。 我在正确的轨道上吗? 仍然不确定在实际单击按钮后如何禁用它。
$('#myButton').click(function() {
});
您走在正确的轨道上。 要在单击后禁用按钮,只需设置disabled
属性。 就像是
$('#myButton').click(function() {
// get a reference to the element on which the handler is bound
// wrap it in a jQuery object so we can call jQuery methods on it.
$(this)
// set the disabled attribute. You can use true or the string 'disabled'
.attr('disabled', true);
});
请记住,当表单中的元素具有焦点时,也可以通过按Enter
键来提交表单。
$('#myButton').click(function() {
$(this).attr('disabled','disabled')
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.