我不明白为什么即使我按了"no“,这个confirm()调用也会触发。你能告诉我我哪里做错了吗?
$('.deleteButton').livequery('click',function(){
if(confirm('Are you sure?')){
return true;
}else
{
return false;
}
return false;
});HTML标记:
<a class="smallbutton deleteButton" href="users.php?todo=delete&id=32">delete</a>我检查了一下,它确实返回了false,但页面仍然重定向到单击的A href值。通常,如果我返回false,它不应该返回,对吗?
发布于 2009-10-27 23:51:47
我道歉:事实证明,我将另一个行为附加到了主内容容器中的所有锚点。我为deleteButton添加了一个排除条款,现在它工作得很好。
以下是我最后的工作代码:
var $tabs= $("#tabs").tabs({
fx: {
opacity: 'toggle'
},
load: function(event, ui) {
$('a', ui.panel).livequery('click',function() {
// we need to exclude the listNav buttons AND deleteButton buttons from this behavior
if($(this).parent().is(':not(".ln-letters")') && $(this).is(':not(".deleteButton")')){
$(ui.panel).load(this.href);
return false;
}
});
}
});而delete按钮的行为使用一个简单的:
$('.deleteButton').live('click',function(e){
return confirm('Are you sure?');
});发布于 2009-10-27 22:40:09
<a id="myId_1" href="#" class="deleteButton">delete</a>
$('.deleteButton').livequery('click',function(e){
e.stopPropagation();
if(confirm('Are you sure?')){
functionForDelete($(this).attr("id").split("_")[1]);
}
});
// OR ir you like goto href
<a id="myId1" href="url/delete/id.php?1" class="deleteButton">delete</a>
$('.deleteButton').livequery('click',function(e){
e.stopPropagation();
if(confirm('Are you sure?')){
window.location=$(this).attr("href");
}
});发布于 2009-10-27 22:43:09
将livequery()更改为live()。jQuery支持相同的功能。只是在FF中测试,它与live()一起工作,但从来没有给我使用livequery()的提示
https://stackoverflow.com/questions/1631190
复制相似问题