gpt4 book ai didi

jquery - 表单按钮禁用在提交时不起作用

转载 作者:行者123 更新时间:2023-12-01 07:43:15 24 4
gpt4 key购买 nike

我试图在发送提交请求后禁用我的按钮。我尝试了下面的示例,但它没有按预期工作。

为什么这段代码没有按预期工作?

$(document).ready(function() {
$('#userSignUp').submit(function() {
$("input[type='submit']", this).val("Please Wait...").attr('disabled', 'disabled');
return true;
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form action="/sign-up" method="post" id="userSignUp">
...
<button type="submit" class="login-sign-up-button">Submit</button>
</form>

最佳答案

这样可以吗?

  $(document).ready(function () {

$("#userSignUp").submit(function (e) {

//stop submitting the form to see the disabled button effect
e.preventDefault();

//disable the submit button
$("#userSignUp").attr("disabled", true);

return true;

});
});

关于jquery - 表单按钮禁用在提交时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43957076/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com