Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 返回确认取消按钮不工作_Javascript_Php_Html_Symfony_Twig - Fatal编程技术网

Javascript 返回确认取消按钮不工作

Javascript 返回确认取消按钮不工作,javascript,php,html,symfony,twig,Javascript,Php,Html,Symfony,Twig,我在twig中有此链接: <a href="{{ path('relation-delete', {'id': c.getCustomerId}) }}" onclick="return confirm('{% trans %}relation.delete{% endtrans %}');" class="tip" data-original-title="Verwijder klant {{ c.getCustomerName }}"> ` “onlick co

我在twig中有此链接:

<a href="{{ path('relation-delete', {'id': c.getCustomerId}) }}" 
   onclick="return confirm('{% trans %}relation.delete{% endtrans %}');"
   class="tip" data-original-title="Verwijder klant {{ c.getCustomerName }}">
`
“onlick confirm cancel”按钮不会取消操作,而是继续执行。
有人知道这个返回确认有什么问题吗?

您可以在函数中验证html元素外部的确认框,并在“onclick”事件中调用此函数。像这样:

<a href="somePage" onclick="return myFunction()">My link</a>

function myFunction() {
    if (confirm("Confirm message")) {
       // do stuff
    } else {
      return false;
    }
}

函数myFunction(){
如果(确认(“确认消息”)){
//做事
}否则{
返回false;
}
}

添加
事件.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);
}

您必须显示结果html,而不是模板将其添加到问题完成中,对此有何想法?控制台中是否存在javascript错误?为什么将
按钮
放在
元素中?结果表明,这是导致其他javascript文件出现问题的原因:
$(“a”)。单击(函数(e){e.preventDefault();location.href=$(this.attr(“href”);})
或那个“return false;”语句会对我起作用,我想,当我第一次阅读它时,我错过了它。。。
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);
}