1

我已经更改了一些默认的 opencart 管理产品列表过滤功能,如下所示:如果我需要从列表中删除产品,我将替换复选框,单击每个产品删除图标,截图附在此处...

在此处输入图像描述

它工作正常,但是如何使用对话框确认删除设置 jquery 函数?,就像我们默认的opencart产品删除确认...当点击删除按钮时询问确认删除?带有确认和取消按钮对话框......有什么想法吗?

我的产品删除按钮与 html 中的列表:

<?php if ($products) { ?>
<?php foreach ($products as $result) { ?>    
<div class="product">      
    <a href="<?php echo $result['delete']; ?>"><img src="delete.png" title="<?php echo $button_delete; ?>" /></a>
    <img src="<?php echo $result['image']; ?>" alt="<?php echo $result['name']; ?>"/>
    <a href="<?php echo $result['view']; ?>"><?php echo $result['name']; ?></a>         
</div>
<?php } ?>
<div class="pagination"></div>
<?php } else { ?>
<div class="empty"><?php echo $text_empty; ?></div>
<?php } ?>

从上面的代码删除按钮:

<a href="<?php echo $result['delete']; ?>"><img src="delete.png" title="<?php echo $button_delete; ?>" /></a>

有任何想法吗?

4

3 回答 3

1

非 jQuery

的HTML:

<a href="#" onclick='confirm_delete("<?php echo $result['delete']; ?>", "<?php echo $result['name']; ?>"); return false;'>
  <img src="delete.png" title="<?php echo $button_delete; ?>" />
</a>

Javascript:

<script>
function confirm_delete(link_to_delete, product_name) {
  var msg=confirm("Are you sure you want to delete " + product_name + " ?");
  if (msg==true)
  {
    window.location.href = link_to_delete;
  }
}
</script>

jQuery

的HTML:

<a class="delete_button" href="<?php echo $result['delete']; ?>">
  <img src="delete.png" title="<?php echo $button_delete; ?>" />
</a>

javascript (jQuery):

<script>
jQuery(".delete_button").on("click", function(e) {
  e.preventDefault();
  var clicked = jQuery(this);
  var clicked_url = clicked.attr("href");
  var product_name = clicked.siblings("img").attr("alt");
  var msg=confirm("Are you sure you want to delete " + product_name + " ?");
  if (msg==true)
  {
    window.location.href = clicked_url;
  }
});
</script>
于 2013-04-14T09:41:25.377 回答
0

你可以利用 jQuery 使用一点:-

$('div.product a img[src="delete.png"]').on('click', function(event){
    if( ! confirm('Delete?')) {
        event.preventDefault();
        return false;
    }
    return true;
});
于 2013-04-14T09:44:57.857 回答
0

下面是我在一行项目上的做法,每个项目都称为“报价”。这是模板代码:

<a href="<?php echo $offer['delete']; ?>" data-toggle="tooltip" title="<?php echo $button_delete; ?>" class="btn btn-primary" onclick="confirm('<?php echo $text_confirm; ?>') ? $('#form-discount_chooser').submit() : false;"><i class="fa fa-trash-o"></i></a>

在调用模板之前,您的控制器将设置$offer['delete']如下:

       $data['offers'][] = array(
           ... 
            'delete' => $this->url->link('extension/module/discount_chooser/delete', 'token=' . $this->session->data['token'] . '&offer=' . $discount['id'] . $url, true)
        );

然后在控制器的 delete() 方法中,一定要处理好这是一个单项,而不是一个或多个复选框的事实:

// Handle onesies
if (!isset($this->request->post['selected'])) {
   if (isset($this->request->get['offer'])) {
     $this->request->post['selected'] = array($this->request->get['offer']);
   }
}
于 2017-05-25T18:23:05.577 回答