使用`Not`和`Delegate` - Jquery

时间:2010-12-28 16:51:30

标签: javascript jquery jquery-ui

我目前有这样的事情:

$(".jtable tbody td").not(".DeleteLicense").hover(

我如何使用委托?像

这样的东西
$("#resultContainer,#approvalContainer,#createNewContainer").delegate(".jtable tbody td....

谢谢!

3 个答案:

答案 0 :(得分:3)

您可以使用:not() selector将否定移至选择器。

$("#resultContainer,#approvalContainer,#createNewContainer")
    .delegate(".jtable tbody td:not(.DeleteLicense)", "...", ...);

请注意,在大多数情况下,jQuery文档建议使用.not()函数而不是:not()选择器,但我不确定在这种情况下是否可行。

如果您愿意使用其他方法,可能会发现您可以在调用delegate时使用.jtable tbody td选择器,然后在事件处理程序中使用if(!$(this).is(".DeleteLicense")) { ... }只处理符合您标准的元素。

答案 1 :(得分:2)

像这样:

$("#resultContainer,#approvalContainer,#createNewContainer").delegate(".jtable tbody td:not('.DeleteLicense')", "hover", function(eventObj) {
    // handler code
});

答案 2 :(得分:0)

我的第一个想法是尝试使用:not() selector

$("#resultContainer,#approvalContainer,#createNewContainer").delegate(".jtable tbody td:not('.DeleteLicense')", "hover", function(){ /* do stuff */});