如果有以下代码,您将如何使用 .not(this) ?

发布于 2024-12-11 02:39:30 字数 694 浏览 0 评论 0原文

在这段代码的情况下,你会怎么说:not(this):

$(".draghandle").droppable({
    accept: ".draghandle:not(this)"
    drop: function ( event, ui ) {
        $( this )
        .addClass( "ui-state-highlight" )
        .find( "p" )
        .html( "Dropped!" );
    }
});

你会看到接受选项旁边的选择器可能无效,尽管我没有检查过,我想知道你是否有解决方案至于验证它?我还没有找到一个,但如果您有一个解决方案也可以更改代码的另一部分,请不要灰心,我只需要修复。 这是我试图扩展的类似问题:jQuery:排除 $(this ) 来自选择器 这是我用作参考的主要代码的链接: http:// /jqueryui.com/demos/droppable/#accepted-elements

How would you say :not(this) in the case of this code:

$(".draghandle").droppable({
    accept: ".draghandle:not(this)"
    drop: function ( event, ui ) {
        $( this )
        .addClass( "ui-state-highlight" )
        .find( "p" )
        .html( "Dropped!" );
    }
});

You'll see the selector right next to the accept option is probably invalid, though I haven't checked to see, I was wondering if you might have a solution as to validating it? I have yet to find one, but don't be discouraged if you have a solution that changes another part of the code as well, I just need a fix.
Here's a similar question I'm trying to expand on: jQuery: exclude $(this) from selector
And here's a link to the main code for this that I'm using as reference: http://jqueryui.com/demos/droppable/#accepted-elements

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

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

发布评论

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

评论(1

梦明 2024-12-18 02:39:30

说明

您可以传递 jQuery 列表作为接受参数,而不仅仅是选择器。在下面的演示中,我将所有 .ui-widget-content 元素设为可删除,除了 #draggable 元素。 (反转原始 jQuery UI 站点演示)。我传递给 accept 的参数是 $(".ui-widget-content").not("#draggable")


演示

http://jsfiddle.net/5TZ7b/
http://jsfiddle.net/5TZ7b/show


代码

$(function() {
    $( "#draggable, #draggable-nonvalid" ).draggable();
    $( "#droppable" ).droppable({
        accept: $(".ui-widget-content").not("#draggable"),
        activeClass: "ui-state-hover",
        hoverClass: "ui-state-active",
        drop: function( event, ui ) {
            $( this )
                .addClass( "ui-state-highlight" )
                .find( "p" )
                .html( "Dropped!" );
        }
    });
});

结论

可以使用以下内容作为传递的参数接受

$(".draghandle").not(this)

Explanation

You can pass a jQuery list as the accept argument instead of just a selector. In the following demo, I make all .ui-widget-content elements droppable except the #draggable one. (reversing the original jQuery UI site demo). the parameter I passed to accept was $(".ui-widget-content").not("#draggable").


Demo

http://jsfiddle.net/5TZ7b/
http://jsfiddle.net/5TZ7b/show


Code

$(function() {
    $( "#draggable, #draggable-nonvalid" ).draggable();
    $( "#droppable" ).droppable({
        accept: $(".ui-widget-content").not("#draggable"),
        activeClass: "ui-state-hover",
        hoverClass: "ui-state-active",
        drop: function( event, ui ) {
            $( this )
                .addClass( "ui-state-highlight" )
                .find( "p" )
                .html( "Dropped!" );
        }
    });
});

Conclusion

You can use the following as the parameter passed to accept.

$(".draghandle").not(this)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文