You can use the localStorage that is able to store a key-value couple. If a key value isn't present in the localStorage null
is returned that has false
boolean value in javascript otherwise whatever string (except empty string "") has true
boolean value.
Furthermore I used prop
instead of attr
because disabled
is a boolean attribute
(like checked selected) and in this case you have to use prop
(otherwise with attr() you set or get the defaultChecked
property namely the initial value of the disabled attribute, and in this case is the same but in general it isn't so)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.min.js"
integrity="sha512-aVKKRRi/Q/YV+4mjoKBsE4x3H+BkegoM/em46NNlCqNTmUYADjBbeNefNxYV7giUp0VxICtqdrbqU7iVaeZNXA=="
crossorigin="anonymous"
></script>
</head>
<body>
<form class="reverse-form">
<input type="submit" />
</form>
<script>
if (localStorage.submitDisabilitato) {
$('form.reverse-form input[type="submit"]').prop("disabled", true);
} else {
$(".reverse-form").one("submit", function (e) {
e.preventDefault();
localStorage.submitDisabilitato = "submitDisabilitato";
$(this).find('input[type="submit"]').prop("disabled", true);
});
}
</script>
</body>