为此代码添加一个确认?
问题描述:
这里是我的jQuery为此代码添加一个确认?
$('.delete_step').live('click', function(e) {
e.preventDefault();
var delete_location = window.location.pathname.replace('admin/', '') + '?route=module/cart/delete_step';
$.post(delete_location, { step_id: $(this).attr("rel"), template_number: "<?php print $template_id; ?>" },
function(result) {
var token = window.location.search.match(/token=(\w+)/)[1];
window.location.href = window.location.pathname + '/index.php?route=system/template&token=' + token;
});
});
这里是我的HTML
<span class="delete"><a rel="<?php print $step['step_number']; ?>" class="delete_step" href="#">Delete Step</a></span>
如何添加一个确认是/否对话框解决这个....任何想法
答
$('.delete_step').live('click', function(e) {
e.preventDefault();
if (confirm('Are you sure?')) {
// do the $.post()
}
}
答
像这样(未测试)
$('.delete_step').live('click', function(e) {
e.preventDefault();
var answer = confirm("Are you sure?")
if (answer){
var delete_location = window.location.pathname.replace('admin/', '') + '?route=module/cart/delete_step';
$.post(delete_location, { step_id: $(this).attr("rel"), template_number: "<?php print $template_id; ?>" },
function(result) {
var token = window.location.search.match(/token=(\w+)/)[1];
window.location.href = window.location.pathname + '/index.php?route=system/template&token=' + token;
});
}else{
alert('fail!');
}
});
答
这将你的函数,然后再继续问他们:
答
$('.delete_step').live('click', function(e) { e.preventDefault(); if(confirm("Message to be popped up?")) { var delete_location = window.location.pathname.replace('admin/', '') + '?route=module/cart/delete_step'; $.post(delete_location, { step_id: $(this).attr("rel"), template_number: "" }, function(result) { var token = window.location.search.match(/token=(\w+)/)[1]; window.location.href = window.location.pathname + '/index.php?route=system/template&token=' + token; }); } });
哈!看起来我被打败了。 – BraedenP 2011-04-25 17:15:40