Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.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_Cakephp - Fatal编程技术网

JavaScript确认删除不工作

JavaScript确认删除不工作,javascript,php,cakephp,Javascript,Php,Cakephp,我使用的是cakephp版本2.x 我在删除任何记录时遇到一个问题。我想在删除记录之前显示确认消息。JavaScript onclick函数不工作。请检查下面的代码 代码: 输出: <a href="/products/deletequery/15"> <img delete?="Are you sure you want to delete?" to="" want="" sure="" you="" are="" alt="Delete" title="Delet

我使用的是cakephp版本2.x

我在删除任何记录时遇到一个问题。我想在删除记录之前显示确认消息。JavaScript onclick函数不工作。请检查下面的代码

代码:


输出:

<a href="/products/deletequery/15">
   <img delete?="Are you sure you want to delete?" to="" want="" sure="" you="" are="" alt="Delete" title="Delete" src="/img/delete.png">
</a>

像这样更改代码,因为您的代码不正确

<?php 
 echo $this->Html->link($this->Html->image('delete.png'),
    array(
        'controller'=>'products',
        'action'=>'deletequery',$query['Query']['id']
    ),
    array('confirm'=>'Are you sure you want to delete?','escape'=>false)
 );
?>

输出

<a 
  onclick="if (confirm('Are you sure you want to delete?')) 
  { return true; } return false;" 
  href="/ABC/products/deletequery">
  <img alt="" src="/ABC/img/delete.png">
</a>

您应该在视图文件中尝试这一点。删除文件基本上有两种方法。 首先,您可以简单地创建cakephp
$this->Html->link
或seceond方法,您可以创建一个
$this->Form->postLink
,两者都是不同的。两者之间的区别是
postLink
创建一个“表单标签”,但
link
标签不创建“表单”标签

1$此->Html->链接

<?php 
 echo $this->Form->postLink($this->Html->image('delete.png').'', array('controller' => 'products', 'action' => 'deletequery',$query['Query']['id']),array('confirm'=>'Are you sure to delete ?','escape'=>false));
 ?> 

2$此->表单->postLink

<?php 
 echo $this->Form->postLink($this->Html->image('delete.png').'', array('controller' => 'products', 'action' => 'deletequery',$query['Query']['id']),array('confirm'=>'Are you sure to delete ?','escape'=>false));
 ?> 

您可以访问cakephp博客教程

你应该读这篇文章:看起来你需要学习如何计算大括号(在本例中是括号)。
<?php 
 echo $this->Form->postLink($this->Html->image('delete.png').'', array('controller' => 'products', 'action' => 'deletequery',$query['Query']['id']),array('confirm'=>'Are you sure to delete ?','escape'=>false));
 ?>