livequery - 确认()

发布于 2024-08-09 00:21:18 字数 494 浏览 8 评论 0原文

我不明白为什么即使我点击“否”,这个确认()调用也会被触发。你能告诉我我做错了什么吗?

$('.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,则不应该,对吧?

I don't get why this confirm() call fires up even though i hit "no". Can you tell me what i'm doing wrong?

$('.deleteButton').livequery('click',function(){
        if(confirm('Are you sure?')){
            return true;
        }else
        {
            return false;
        }
        return false;
    });

The HTML Markup:

<a class="smallbutton deleteButton" href="users.php?todo=delete&id=32">delete</a>

I checked and it does return false, but the page still redirects to the clicked A href value. Normally, if i return false, it shouldn't, right?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

萌︼了一个春 2024-08-16 00:21:18
<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");
        }
});
<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");
        }
});
十年九夏 2024-08-16 00:21:18

将 livequery() 更改为 live()。 jQuery 支持相同的功能。刚刚在 FF 中进行了测试,它可以与 live() 一起使用,但甚至从未给过我 livequery() 的提示

Change livequery() to live(). jQuery supports the same functionality. Just tested in FF and it worked with live() but never even gave me a prompt with livequery()

╭⌒浅淡时光〆 2024-08-16 00:21:18

我道歉:事实证明我正在将另一种行为附加到主内容容器内的所有锚点。我为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;
                }
            });
        }
    });

删除按钮行为的工作原理很简单:

$('.deleteButton').live('click',function(e){
    return confirm('Are you sure?');
});

I apologize: it turns out i was attaching another behaviour to all anchors inside the main content container. I added an exclusion clause for deleteButton and it works fine now.

Here is my final, working, code:

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;
                }
            });
        }
    });

And the delete button behaviour works with a simple:

$('.deleteButton').live('click',function(e){
    return confirm('Are you sure?');
});
纸短情长 2024-08-16 00:21:18

试试这个:

$('.deleteButton').livequery('click',function(e){
    if (confirm('Are you sure?')) {
        return true;
    } else {
        if (e.preventDefault) {
            e.preventDefault();
        } else {
            e.returnValue = false;
        }
        return false;
    }
});

Try this:

$('.deleteButton').livequery('click',function(e){
    if (confirm('Are you sure?')) {
        return true;
    } else {
        if (e.preventDefault) {
            e.preventDefault();
        } else {
            e.returnValue = false;
        }
        return false;
    }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文