Jquery选择器和条件

Pri*_*ank 3 jquery

我们在应用程序中要求点击所有没有css类"xyz"的图像我们想要调用一个函数.我们试着写一下这样的东西:

$('input[type=image] class=xyz').click(function(){//something});
Run Code Online (Sandbox Code Playgroud)

它似乎不起作用.理想的情况是,点击时的所有图像都会执行一些功能,除了CSS为"xyz"的图像.

我究竟做错了什么?

我正在使用输入,因为我使用JSF并且此命令按钮显示为输入类型组件,其中src为image.

感谢您的帮助.干杯

And*_*ell 7

我想你想使用没有.

这应该这样做:

$('input[type=image]').not(".xyz").click(function(){//something});
Run Code Online (Sandbox Code Playgroud)

您也可以使用not选择器.

$('input[type=image]:not(.xyz)').click(function(){//something});
Run Code Online (Sandbox Code Playgroud)

功能版似乎对我更有表现力.