jquery .not() 不工作
$(document).not('.myform-links').click(function (event) {
$('.myform-links').toggle();
});
在某个时刻,单击一个元素会切换 .myform-links div
元素的显示。
该元素使用 CenterIt jquery 插件使 div
元素浮动位于页面顶部中央。
我试图使用上面的代码来检测不在浮动元素中的任何位置的点击,以便它可以切换回隐藏状态。
编辑:
$(document).not('.myform-links').click(function() {
$('.myform-links').toggle();
});
$(document).ready(function () {
$('.myform-links').CenterIt();
$('.myform-links').hide();
});
$('#toggle').live('click',function() {
$('.myform-links').toggle();
});
这是我用来操作元素的所有代码,第一个发布的代码是不起作用的代码。
根据 .not() 文档,我认为没有理由这不起作用。看起来要么该元素被 CenterIt() 更改,要么创建的对象模型中没有 .myform-links。
$(document).not('.myform-links').click(function (event) {
$('.myform-links').toggle();
});
At some point, an element is clicked which toggles the .myform-links div
element to show.
This element is using the CenterIt jquery plugin to make the div
element float centered on top of the page.
I'm trying to use the above code to detect a click that is anywhere that is not in the element that is floating so that it may toggle back to its hidden status.
EDIT:
$(document).not('.myform-links').click(function() {
$('.myform-links').toggle();
});
$(document).ready(function () {
$('.myform-links').CenterIt();
$('.myform-links').hide();
});
$('#toggle').live('click',function() {
$('.myform-links').toggle();
});
This is all of the code I am using to manipulate the element and the first posted code is the code that is not working.
based on the .not() documentation, I see no reason why this should not work. It would appear that either the element is changed by the CenterIt() or the object model that is created does not have the .myform-links in it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的语法不太正确。你应该使用 not();选择器中的函数,
即除非您要重用该事件,否则不需要在函数中声明它。
Your syntax isn't quite right. You should to use the not(); function within a selector, i.e.
And unless you're going to reuse the event you don't need to state it in the function.
此代码将不起作用,因为单击事件是冒泡直到文档并且它将触发该事件。尝试下面的代码
This code will not work because the click event is bubble till document and it will trigger the event. Try the below code