[英]JavaScript confirm delete not working
I am using cakephp version 2.x. 我正在使用cakephp 2.x版本。
I am getting one trouble while deleting any record. 删除任何记录时遇到麻烦。 I want to show confirmation message before delete my record. 我想在删除记录之前显示确认消息。 The JavaScript onclick function not working. JavaScript onclick函数不起作用。 Please check below code. 请检查以下代码。
Code: 码:
<?php
echo $this->Html->image('delete.png', array(
'title' => 'Delete',
'alt' =>'Delete' ,
'url' => array(
'controller' => 'products',
'action' => 'deletequery/'.$query['Query']['id']),array('confirm' => 'Are you sure you want to delete?')
)
);
?>
OutPut: 输出:
<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>
Change your code like this because your code is incorrect. 像这样更改您的代码,因为您的代码不正确。
<?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)
);
?>
Output 输出量
<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>
You should try this in your view file there are basically two methods to delete a file. 您应该在视图文件中尝试此操作,基本上有两种删除文件的方法。 first is you can simply make cakephp
$this->Html->link
or seceond method you can make a$this->Form->postLink
both are different. 首先,您可以简单地使cakephp$this->Html->link
或第二种方法使$this->Form->postLink
都不同。 the difference between both arepostLink
creates a "Form tag" butlink
tag not create "Form" tag 两者之间的区别是postLink
创建“表单标签”,而link
标签未创建“ Form”标签1. $this->Html->link 1. $ this-> Html-> link
<?php
echo $this->Html->link($this->Html->image('delete.png').'', array('controller' => 'products', 'action' => 'deletequery',$query['Query']['id']),array('confirm'=>'Are you sure to delete ?','escape'=>false));
?>
2. $this->Form->postLink 2. $ this-> Form-> 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));
?>
you can visit cakephp blog tutorial cakephp blog tutorial 您可以访问cakephp博客教程cakephp博客教程
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.