簡體   English   中英

提交表單前無法返回確認對話框

[英]Returning a confirmation dialog before submitting form not working

我正在嘗試讓網站在提交表單之前返回確認對話框,但是由於某些原因,它無法正常工作。 它返回了確認對話框,但是單擊“是”后,它不提交表單。 我究竟做錯了什么?

<?php

echo "
<form action = 'delete.php' method = 'POST'>
<label id = 'delete' onclick = \"return confirm('Are you sure?');this.form.submit()\"> delete </label>
</form>
";

?>

注意:

與其使用input:submit,不如使用標簽onclick()和確認對話框。 那可能嗎? 謝謝。

您代碼中的onclick處理程序僅返回confirm對話框結果,並忽略代碼的其余部分( this.form.submit()this.form.submit() 我建議在這種情況下使用外部函數:

<?php

echo "
<form action = 'delete.php' method = 'POST'>
<label id = 'delete' onclick = \"confirmSubmit(this);\"> delete </label>
</form>
";

?>

js代碼:

function confirmSubmit(e){
    var need_submit = confirm('Are you sure?');
    if (need_submit) e.form.submit();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM