javascript - 重复(模仿)OpenCart 确认删除

标签 javascript jquery button opencart

我想复制 OpenCart 的 jQuery 来确认操作。这是 JavaScript:

<script type="text/javascript">
//-----------------------------------------
// Confirm Actions (delete, uninstall)
//-----------------------------------------
$(document).ready(function(){
    // Confirm Delete
    $('#form').submit(function(){
        if ($(this).attr('action').indexOf('delete',1) != -1) {
            if (!confirm('<?php echo $text_confirm; ?>')) {
                return false;
            }
        }
    });
        });
    </script>

HTML 是:

<a onclick="$('form').attr('action', '<?php echo $delete; ?>'); $('form').submit();" class="button"><?php echo $button_delete; ?></a>

我的按钮是:

<a onclick="$('form').attr('action', '<?php echo $process_carts_action; ?>'); $('form').submit();" class="button"><?php echo "Process Carts" ?></a>

这是引用按钮的行以及如何引用吗?

if ($(this).attr('action').indexOf('delete',1) != -1)

最佳答案

答案当然很简单。

if ($(this).attr('action').indexOf('delete',1) != -1)

上面的代码翻译过来就是(错误的地方请指正)

if // IF
$(this) // this instance of the document object, form referenced by ID (#)
.attr('action') // which has been assigned an attribute named 'action'
.indexOf('delete',1) // we'll use the indexOf function to see if it contains string 'delete'
!= -1 // and if it doesn't return "-1", which means 'false'
if (!confirm('<?php echo $text_confirm; ?>')) //THEN 
// call the javascript 'confirm' function and fill it with text contained in php var $text_confirm

所以解决办法是

$(document).ready(function(){
    // Confirm Process
    $('#form').submit(function(){
        if ($(this).attr('action').indexOf('process_carts',1) != -1) {
            if (!confirm("Are you sure you're ready to process all carts?")) {
                return false;
            }
        }
    });
 });

其中 process_carts#form 中唯一的字符串,位于 var $process_carts_action

关于javascript - 重复(模仿)OpenCart 确认删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24847650/

相关文章:

javascript - 单击jquery双重执行

R - 计算 Shiny 下载按钮的点击次数

php - 如何使用mysql在php中使用按钮删除一行

c# - 获取控件的信息

javascript - 是否可以使用 right 和 top 属性设置弹出窗口位置?

JavaScript 到 jquery 的问题

javascript - 如何在某个特定组件发出某些内容时让其他组件监听,包括 Stackblitz 演示

javascript - 解释为什么这个 HTML 只能在 Firefox 中使用,而不能在任何其他浏览器中使用?

javascript - js原型(prototype),设置名称

javascript - 从按钮单击调用 jquery facbox