[英]Disable button after submit with form that has PHP function. No jQuery
我有一個在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>
document.getElementById("yourButtonId").disabled = true;
從這里獲取: https : //www.w3schools.com/jsref/prop_pushbutton_disabled.asp
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.