向此代码添加确认
adding a confirm to this code?
这是我的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>
如何在此周围添加确认是/否对话框....任何想法
使用window.confirm()
$('.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("要弹出的消息?")){Var delete_location = window.location.pathname。替换('admin/', ') + '?route=module/cart/delete_step';美元。Post (delete_location, {step_id: $(this).attr("rel"), template_number: "},函数(结果){Var token= window.location.search.match(/token=('w+)/)[1];Window.location.href = window.location.pathname + '/index.php?Route =system/template&token=' + token;});}});
这将在继续执行函数之前询问他们:
$('.delete_step').live('click', function(e) {
e.preventDefault();
var response = confirm("Are you sure you want to delete this?");
if(response){
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;
});
}
});
相关文章:
- jQuery:确认.html()是否可添加
- 如何在批准露天共享中工作流的审核步骤之前添加确认对话框
- Rails:将表单字段值添加到数据确认消息中
- 仅当条件为真时,才将客户端单击确认添加到 asp.net 按钮
- 如何在提交时向Happy.js添加确认消息
- 向asp.net生成的链接添加确认javascript
- 如何在脚本中添加确认是或否
- 如何在确认框中点击“是”后将元标记添加到文档中
- 如何添加Facebook FB.ui对话框确认消息
- 如何在我的联系表单上添加确认框
- 分机.js确认方法添加新行字符
- ASP Html.BeginForm 多个提交按钮 - 添加没有 JQuery 的自定义确认
- 仍然没有添加到 DOM 中,但如果插入了警报/确认,则会获取标签 ID
- JQuery :添加具有绑定/打开和触发器函数的确认处理程序
- 如何使用jQuery同时向多个不同的按钮添加确认对话框
- 在jQuery 1.4.2中添加一个简单的确认/取消对话框
- 在Ajax.BeginForm的“确认”对话框中添加对象routedValue
- 如何将确认按钮添加到WebUI Popover jQuery插件中
- 如何将onclick事件添加到Javascript确认框的OK按钮中
- 做新的窗口重定向确认添加点