gpt4 book ai didi

javascript - 防止表单提交有效...太好了

转载 作者:行者123 更新时间:2023-11-28 11:25:17 25 4
gpt4 key购买 nike

我有一个表单,我不想在第一次单击提交时提交,但第二次它应该像正常提交一样工作。因此,我在加载时向表单添加了一个 not-submittable 类,然后在第一次单击后删除该类...这应该(我认为)使其正常提交。但是,这不会发生。第一次单击按预期工作,删除类并更改按钮文本。然而,第二次单击会执行完全相同的操作。那么,我在这里缺少什么?

jQuery:

  $('form#survey_7042 #ACTION_SUBMIT_SURVEY_RESPONSE').addClass('not-submittable');

$('form#survey_7042 #ACTION_SUBMIT_SURVEY_RESPONSE.not-submittable').click(function(event) {
$('form#survey_7042 #ACTION_SUBMIT_SURVEY_RESPONSE').removeClass('not-submittable');
$('form#survey_7042 #ACTION_SUBMIT_SURVEY_RESPONSE').val('Continue');
$('form#survey_7042 #ACTION_SUBMIT_SURVEY_RESPONSE').removeAttr('disabled');
return false;
});

JavaScript 之前的按钮:

<input type="submit" class="Button" value="Submit Survey" id="ACTION_SUBMIT_SURVEY_RESPONSE" name="ACTION_SUBMIT_SURVEY_RESPONSE">

最佳答案

Quote OP: "I have a form that I don't want to be submitted the first time submit is clicked, but the second time it should work like a normal submit."

使用 jQuery .one() 仅在第一次点击时阻止提交

http://api.jquery.com/one/

$('#ACTION_SUBMIT_SURVEY_RESPONSE').one('submit', function(e) {
e.preventDefault();
// do what you need to do on first click
}

或者...

$('#ACTION_SUBMIT_SURVEY_RESPONSE').one('submit', function(e) {
e.preventDefault();
// do what you need to do on first click
if ( some-condition ) { // under certain conditions allow submit on first click
$(this).submit();
}
}

关于javascript - 防止表单提交有效...太好了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14650942/

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