[英]Return confirm cancel button not working
我在樹枝上有這個鏈接:
<a href="{{ path('relation-delete', {'id': c.getCustomerId}) }}"
onclick="return confirm('{% trans %}relation.delete{% endtrans %}');"
class="tip" data-original-title="Verwijder klant {{ c.getCustomerName }}">
源代碼中的HTML:
<a href="/app_dev.php/projects/delete/1" class="tip"
data-original-title="Verwijder project Lantaarn plaatsen"
onclick="return confirm('Verwijderen');">
<button class="btn btn-danger"><i class="fa fa-times fa-fw"></i></button></a>`
onlick確認取消按鈕不會取消操作,而是繼續執行。 有人知道此退貨確認有什么問題嗎?
您可以在函數中驗證html元素外部的確認框,並在“ onclick”事件中調用此函數。 像這樣:
<a href="somePage" onclick="return myFunction()">My link</a>
function myFunction() {
if (confirm("Confirm message")) {
// do stuff
} else {
return false;
}
}
添加event.preventDefault();
修復。
這是一個例子:
console.log('Validating...');
function confirm_delete(){
var txt;
var r = confirm("Are you sure you want to delete?");
if (r == true) {
txt = "You pressed OK!";
} else {
txt = "You pressed Cancel!";
event.preventDefault();
}
console.log(txt);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.