esa*_*wan 18 jquery popup confirmation preventdefault
我有这样的链接.
<a href="delete.php?id=1" class="delete">Delete</a>
Run Code Online (Sandbox Code Playgroud)
如果用户点击它.应该弹出确认,然后只有当用户单击是时,它才会转到实际的URL.
我知道这可以防止默认行为
function show_confirm()
{
var r=confirm("Are you sure you want to delete?");
if (r==true) { **//what to do here?!!** }
}
$('.delete').click(function(event) {
event.preventDefault();
show_confirm()
});
Run Code Online (Sandbox Code Playgroud)
但是如何确认后我如何继续链接或发送ajax帖子到该链接?
loc*_*zak 34
你可以在点击内完成所有操作:
$('.delete').click(function(event) {
event.preventDefault();
var r=confirm("Are you sure you want to delete?");
if (r==true) {
window.location = $(this).attr('href');
}
});
Run Code Online (Sandbox Code Playgroud)
或者您可以通过将单击的元素传递给函数来实现:
function show_confirm(obj){
var r=confirm("Are you sure you want to delete?");
if (r==true)
window.location = obj.attr('href');
}
$('.delete').click(function(event) {
event.preventDefault();
show_confirm($(this));
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
30306 次 |
最近记录: |