我想复制 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/