我有一个在 PHP 中回显的 HTML 表单,该表单操作调用一个 PHP 函数。如果可能的话,我想在单击提交按钮后禁用它,而不使用 jQuery。
#PHP
echo '
<form method="POST" action="' . phpFunction() . '">
//form fields
<button name="submit" type="submit" class="btn btn-primary btn-block">Enviar</button>
</form>';
我尝试在按钮上使用onclick="this.disabled=true"
,但它阻止了 PHP 函数的执行。
我应该怎么做才能执行该功能并禁用该按钮?
最佳答案
使用这个简单的代码禁用提交按钮
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
function form_submission(form_id, button_id) {
$('#btn_add').attr('disabled', 'disabled');
document.getElementById(button_id).style.display = "none";
document.forms[form_id].submit();
}
</script>
</head>
<body>
<form action="submit.php" method="post" name="form_name" id="form_name">
<input type="text" name="first_name" />
<input type="text" name="last_name" />
<input type="button" name="btn_add" id="btn_add" value="save" onclick="form_submission('form_name', 'btn_add')" />
</form>
</body>
关于javascript - 使用具有 PHP 功能的表单提交后禁用按钮。没有 jQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59081490/