【发布时间】:2010-11-20 02:05:46
【问题描述】:
例如我有这个代码:
<style>
.wrapper { width:1200px; height:800px; }
.column { width:900px; height:800px; margin:auto -0; }
</style>
<div class="wrapper">
<div class="column"> </div>
</div>
我希望在您单击“列”外部而不是列内部时调用 mousedown 函数。这可能吗?
我当前的非工作代码是:
$(".wrapper:not(.column)").mousedown(function(){
alert("test");
});
更新:我实际上使用的是类,而不是 ID。
【问题讨论】:
-
你不需要 :not(#column) - #wrapper 就足够了,因为它是按 id 选择的。
-
在我的实际代码中,我使用的是类。这会影响什么吗?
-
仍然,您的选择器不会选择 .column div,因为它没有“包装器”类,因此您仍然不需要 :not(.column)。
-
使用类意味着你需要一个更通用的方法,看看我的回答看看如何。
标签: javascript jquery css-selectors