如果有以下代码,您将如何使用 .not(this) ?
在这段代码的情况下,你会怎么说: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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
说明
您可以传递 jQuery 列表作为接受参数,而不仅仅是选择器。在下面的演示中,我将所有
.ui-widget-content
元素设为可删除,除了#draggable
元素。 (反转原始 jQuery UI 站点演示)。我传递给accept
的参数是$(".ui-widget-content").not("#draggable")
。演示
http://jsfiddle.net/5TZ7b/
http://jsfiddle.net/5TZ7b/show
代码
结论
可以使用以下内容作为传递的参数
接受
。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 toaccept
was$(".ui-widget-content").not("#draggable")
.Demo
http://jsfiddle.net/5TZ7b/
http://jsfiddle.net/5TZ7b/show
Code
Conclusion
You can use the following as the parameter passed to
accept
.